Java强化练习

1、两个变量里的数,不通过第三个变量交换

public static void main(String[] args) {

              int a = 100;

              int b = 200;

              a+=b;

              b=a-b;

              a=a-b;

              System.out.println(a);

              System.out.println(b);

//哈哈,这么简单,是不是感觉到一种淡淡的忧伤

//其实,并不难,只需要换个想法

2、判断学生成绩 成绩>90 A 成绩>80 B 成绩>70 C 成绩>60 D 成绩<60 E

public static void main(String[] args) {

              System.out.println("请输入学生成绩:");

              Scanner scanner = new Scanner(System.in);

              double i = scanner.nextDouble();

              int a = (int) i / 10;

              if (a > 10 || a < 0) {

                     System.out.println("您输入的成绩,闹呢?重新输入");

              } else {

                     if (a > 9) {

                            System.out.println("成绩为A");

                     } else if (a > 8) {

                            System.out.println("成绩为B");

                     } else if (a > 7) {

                            System.out.println("成绩为C");

                     } else if (a > 6) {

                            System.out.println("成绩为D");

                     } else if (a < 6) {

                            System.out.println("成绩为E");

                     }

              }

3、输入一个整数,判断是否是偶数

     Scanner scanner = new Scanner(System.in);

     int a = scanner.nextInt();

              if(a%2==0){

                     System.out.println("是偶数");

              }else{

                     System.out.println("不是偶数");

              }

4、输入学生成绩,使用switch判断

判断学生成绩 成绩>90 A 成绩>80 B 成绩>70 C 成绩>60 D 成绩<60 E

public static void main(String[] args) {

                System.out.println("请输入学生成绩:");

                Scanner scanner = new Scanner(System.in);

                double i = scanner.nextDouble();

                switch ((int)i/10) {

                case 9:System.out.println("成绩为A");             

                     break;

                case 8:System.out.println("成绩为B");             

                    break;

                case 7:System.out.println("成绩为C");             

                    break;

                case 6:System.out.println("成绩为D");             

                    break;

                default:System.out.println("不及格");

                    break;

              }

5、根据年份、月份,求出当月天数

     System.out.println("请输入年份:");

              Scanner scanner = new Scanner(System.in);

              int year = scanner.nextInt();

              System.out.println("请输入月份:");

              int mo = scanner.nextInt();

              switch (mo) {

              case 1:             

              case 3:             

              case 5:             

              case 7:             

              case 8:             

              case 10:             

              case 12:System.out.println("本月31天");             

                     break;      

              case 4:             

              case 6:             

              case 9:             

              case 11:System.out.println("本月30天");             

                     break;

              case 2:      

                     //判断是否是闰年

                     if(year % 4 ==0 && year % 100 != 0 || year%400 == 0){

                            System.out.println("本月29天");

                     }else{

                            System.out.println("本页28天");

                     }

                     break;

              default:System.out.println("输入错误");

                     break;

              }

       }

 6、水仙花数

public static void main(String[] args)

{

int i,j,k,n;

for(n=100;n<1000;n++)

{

i=n/100;/*分解出百位*/

j=n/10%10;/*分解出十位*/

k=n%10;/*分解出个位*/

if(i*100+j*10+k==i*i*i+j*j*j+k*k*k)

   { 

System.out.println(n);

   }

}

System.out.println();

}

7、99乘法表

public static void main(String[] args)

{

System.out.println("99乘法表:");

int x,y;

for(x = 0;x <= 9; x++)

{

for(y = 1;y <= x; y++)

{

System.out.print(y+"*"+x+"="+x*y+"\t");

}

System.out.println();

}

}

8、百钱买百鸡

public static void main(String[] args)

{

int x, y, z;

for (x = 1; x < 20; x++) {

for (y = 1; y < 33; y++) {

for (z = 3; z < 300; z = z + 3) {

if ((5 * x + 3 * y + z / 3 == 100) && (x + y + z == 100)) {

System.out.println("公鸡数:" + x + "母鸡数" + y + "小鸡数" + z);

}

}

}

}

}

转载于:https://www.cnblogs.com/ht57988/p/5588057.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值