第八波十道练习题

题目:809*??=800*??+9*??
其中??代表的两位数,8*??的结果为两位数,9*??的结果为3位数
求??代表的两位数,及809*??后的结果
package cn.tedu.pativate;
//题目:809*??=800*??+9*??
//其中??代表的两位数,8*??的结果为两位数,9*??的结果为3位数
// 求??代表的两位数,及809*??后的结果
public class Parivate0 {
    public static void main(String[] args) {
        for (int i = 10; i < 100; i++) {
            if (i*8<100 && i*9>100){
                System.out.println("??代表的两位数为"+i);
                System.out.println("809*??的结果为"+(i*809));
            }
        }
    }
}
题目:求0—7所能组成的奇数个数。
组成1位数是4个。
组成2位数是7*4个。
组成3位数是7*8*4个。
组成4位数是7*8*8*4个.
package cn.tedu.pativate;
//题目:求0—7所能组成的奇数个数。
//组成1位数是4个。
//组成2位数是7*4个。
//组成3位数是7*8*4个。
//组成4位数是7*8*8*4个。
public class Parivate1 {
    public static void main(String[] args) {
        int sum=4;
        int j;
        System.out.println("组成1位数是 "+sum+" 个");
        sum=sum*7;
        System.out.println("组成2位数是 "+sum+" 个");
        for(j=3;j<=9;j++) {
            sum = sum * 8;
            System.out.println("组成" + j + "位数是 " + sum + " 个");
        }
    }
}
题目:判断一个整数能被几个9整除
package cn.tedu.pativate;
import java.util.Scanner;
//题目:判断一个整数能被几个9整除
public class Parivate2 {
    public static void main(String[] args) {
        System.out.println("请输入一个正整数");
        long l = new Scanner(System.in).nextLong();
        int i = 0;
        boolean b = true;
        while (b){
            if(l % 9 == 0){
                l = l / 9;
                i++;
            }else{
                b = false;
            }
        }
        System.out.println("正整数"+l+"能被"+i+"个9整除");
    }
}
题目:两个字符串连接程序
package cn.tedu.pativate;
import java.util.Scanner;
//题目:两个字符串连接程序
public class Parivate3 {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        System.out.print("请输入一个字符串:");
        String str1 = s.nextLine();
        System.out.print("请再输入一个字符串:");
        String str2 = s.nextLine();
        String str = str1+str2;
        System.out.println("连接后的字符串是:"+str);
    }
}
题目:读取7个数(1—50)的整数值,每读取一个值,程序打印出该值个数的*
package cn.tedu.pativate;
//题目:读取7个数(1—50)的整数值,每读取一个值,程序打印出该值个数的*
public class Parivate4 {
    public static void main(String[] args) {
        for (int i = 0; i < 7; i++) {
            int x = (int)(Math.random()*49)+1;
            System.out.println(x+":");
            for (int j = 0; j < x; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}
题目:某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的
加密规则如下:每位数字都加上5,然后用和除以10的余数代替该数字
再将第一位和第四位交换,第二位和第三位交换
package cn.tedu.pativate;
import java.util.Scanner;
//题目:某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的
// 加密规则如下:每位数字都加上5,然后用和除以10的余数代替该数字
// 再将第一位和第四位交换,第二位和第三位交换
public class Parivate5 {
    public static void main(String[] args) {
        int x ;
        do {
            System.out.println("请输入一个四位正整数");
            x = new Scanner(System.in).nextInt();
        }while (x<1000 || x>9999);
        int[] a = new int[4];
        a[0] = (x % 10 +5)%10;
        a[1] = (x / 10 % 10 + 5) % 10;
        a[2] = (x / 100 % 10 +5) % 10;
        a[3] = (x / 1000 +5) %10;
        System.out.println("加密后的数字为:"+a[0]+""+a[2]+""+a[1]+""+a[3]);
    }
}
题目:计算字符串中子串出现的次数
package cn.tedu.pativate;
import java.util.Scanner;
//题目:计算字符串中子串出现的次数
public class Parivate6 {
    public static void main(String[] args) {
        System.out.println("请输入一个字符串");
        String str = new Scanner(System.in).nextLine();
        System.out.println("请输入一个子字符串");
        String s = new Scanner(System.in).nextLine();
        int count = 0;
        if (str.equals("") || s.equals("") || str.length()<s.length()){
            System.out.println("您输入的字符串或子字符串有误,无法比较!");
            System.exit(0);
        }else {
            int a = str.length();
            str = str.replace(s,"");
            a = a - str.length();
            count = a / s.length();
        }
        System.out.println("子串在字符串中出现: "+count+" 次");
    }
}
题目:有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,三门课成绩)
计算出平均成绩,把原有的数据和计算出的平均分数存放在磁盘文件 "stud "中
package cn.tedu.pativate;
import java.io.*;
import java.util.Scanner;
//题目:有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,三门课成绩)
// 计算出平均成绩,把原有的数据和计算出的平均分数存放在磁盘文件 "stud "中
public class Parivate7 {
    public static void main(String[] args) {
        String[][] str = new String[5][6];
        for (int i = 0; i < 5; i++) {
            System.out.println("请输入第"+(i+1)+"个学生学号");
            str[i][0] = new Scanner(System.in).nextLine();
            System.out.println("请输入"+(i+1)+"个学生姓名");
            str[i][1] = new Scanner(System.in).nextLine();
            for (int j = 0; j < 3; j++) {
                System.out.println("请输入该学生的第"+(j+1)+"个成绩");
                str[i][j+2] = new Scanner(System.in).nextLine();
            }
            System.out.println("-------------------------------");
        }
        double avg;
        double sum;
        for (int i = 0; i < 5; i++) {
            sum = 0.0;
            for (int j = 2; j < 5; j++) {
                sum = sum + Double.parseDouble(str[i][j]);
            }
            avg = sum/3;
            str[i][5] = String.valueOf(avg);
        }
        String s1;
        BufferedWriter out = null;
        try{
            out = new BufferedWriter(
                    new FileWriter("E:\\360Downloads\\Perfoo\\1.txt",true));
            for (int i = 0; i < str.length; i++) {
                for (int j = 0; j < str[i].length; j++) {
                    s1 = str[i][j] + "\t";
                    out.write(s1);
                }
                out.write("\r\n");
            }
            System.out.println("数据写入成功");
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if (out!=null){
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }finally {
                    out = null;
                }
            }
        }
    }
}
第1个人10,第2个比第1个人大2岁,依次递推,请用递归方式计算出第8个人多大
package cn.tedu.pativate;
//第1个人10,第2个比第1个人大2岁,依次递推,请用递归方式计算出第8个人多大
public class Parivate8 {
    public static void main(String[] args) {
        int age = recursion(8);
        System.out.println("第八个人的年龄为:"+age);
    }

    private static int recursion(int i) {
        if (i == 1) return 10;
        return recursion(i-1) + 2;
    }
}
已知:斐波那契数列的前几个数分别为0,1,1,2,3,5…从第三项开始,每一项都等于前两项的和
请接收用户输入的整数n,求出此数列的前n项.
package cn.tedu.pativate;
import java.util.Scanner;
//已知:斐波那契数列的前几个数分别为0,1,1,2,3,5…从第三项开始,每一项都等于前两项的和
// 请接收用户输入的整数n,求出此数列的前n项.
public class Parivate9 {
    public static void main(String[] args) {
        System.out.println("请输入要求取的项数");
        int n = new Scanner(System.in).nextInt();
        int x = 0;
        int y = 1;
        if (n == 1){
            System.out.println(x);
            return;
        }
        if (n ==2 ){
            System.out.println(x);
            System.out.println(y);
            return;
        }
        System.out.println(x);
        System.out.println(y);
        for (; (n-2 >0) ; n--) {
            int z = x+y;
            x = y;
            y = z;
            System.out.println(z);
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值