• 05


    一、

    1、switch

    2、long

    3、表达式1

    4、break

    5、continue

    二、

    1、B

    2、A

    3、BD

    4、D

    5、B

    6、A

    7、A

    8、D

    9、D

    10、B

    三、

    1、Y  2、Y  3、N  4、 Y  5、Y  6、N

    四、

    1、相同点:都是用来处理多分支条件的结构。

       不同点:switch只能处理等值条件判断情况。而且条件只能是整形或者是字符型变量

               多重if可以处理变量在某个连续区间的情况。

    2、do-while 至少执行一次循环体。

    3、break 跳出循环 continue 结束本次循环。

    五、

    1、import java.util.Scanner;

    class Demo3

    {

             public static void main(String[] args)

             {

                       Scanner sc = new Scanner(System.in);

                       System.out.println("请输入一个数字:");

                       int a = sc.nextInt();

                       if (a%2==0){

                                System.out.println(a+"是一个偶数");

                       }else{

                                System.out.println(a+"是一个奇数");

                       }

             }

    }

    2、import java.util.Scanner;

    class Demo4

    {

             public static void main(String[] args)

             {

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

                       Scanner sc = new Scanner(System.in);

                       int a = sc.nextInt();

                       if (a>=90&&a<=100){

                                System.out.println("A级");

                       }else if (a>=80&&a<90){

                                System.out.println("B级");

                       }else if (a>=70&&a<80){

                                System.out.println("C级");

                       }else if (a>=60&&a<70){

                                System.out.println("D级");

                       }else if (a>=0&&a<60){

                                System.out.println("E级");

                       }else{

                                System.out.println("您输入的数值有误!");

                       }

             }

    }

    import java.util.Scanner;

    class Demo5

    {

             public static void main(String[] args)

             {

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

                       Scanner sc = new Scanner(System.in);

                       int a = sc.nextInt();

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

                                System.out.println("您输入的数值有误!");

                                return;

                       }

                       String grade="";

                       switch (a/10){

                       case 10:

                       case 9:{

                       grade="A级";

                       break;

                       }

                       case 8:{            

                       grade="B级";

                       break;

                       }

                       case 7:{   

                       grade="C级";

                       break;

                       }

                       case 6:{   

                       grade="D级";

                       break;

                       }

                       case 5:

                       case 4:

                       case 3:

                       case 2:

                       case 1:

                       case 0:{

                       grade="E级";

                       break;

                       }

                       }

                       System.out.println("成绩"+a+"属于"+grade);

             }

    }

    3、

    import java.util.Scanner;

    class Demo6

    {

             public static void main(String[] args)

             {

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

                       Scanner sc = new Scanner(System.in);

                       int month = sc.nextInt();

                       String season="";

                       if (month>12||month<1){

                                System.out.println("您输入的数值有误,请重新输入!");

                                return;

                       }

                       switch (month){

                       case 3:

                       case 4:

                       case 5:{

                       season="春天-春暖花开 踏青 植树";

                       break;

                       }

                       case 6:

                       case 7:

                       case 8:{            

                       season="夏天-夏日炎炎 吃雪糕 游泳";

                       break;

                       }

                       case 9:

                       case 10:

                       case 11:{ 

                       season="秋天-秋高气爽 睡觉 打游戏";

                       break;

                       }

                       case 12:

                       case 1:

                       case 2:{   

                       season="冬天-寒风凌冽 滑雪 堆雪人";

                       break;

                       }

                      

                       }

                       System.out.println("月份"+month+"属于"+season);

             }

    }

    4、

    import java.util.Scanner;

    class Demo7

    {

             public static void main(String[] args)

             {

                       Scanner sc = new Scanner(System.in);

                       int n=0;

                       int sum=0;

                       int temp;

                      

                       while (n<5){

                                n++;

                       System.out.println("请输入第"+n+"个学生分数:");

                       int s=sc.nextInt();   

                       temp=s;

                       sum+=temp;

                       }

                       System.out.println("五个学生的和分数为:"+sum);

                                        

             }

    }

  • 相关阅读:
    SqlParameter构造函数让人大吃一斤
    ASP.NET的图片上传和显示
    不去琢磨什么CSS后代选择器之类的鸟玩意了
    datatable里添加一个标识列
    提高工作效率
    调试无法命中断点问题
    离DBA还有多远?
    开发守则
    方法或函数也可以用泛型
    母版页访问内容页
  • 原文地址:https://www.cnblogs.com/songzongyuan-java/p/9275155.html
Copyright © 2020-2023  润新知