1、Scanner(接收用户输入的数据)
1)共三步:
--------------①import java.util.Scanner;【在public class上一行】
--------------②Scanner scan = new Scanner(System.in); 【在main中】
--------------③int command = scan.nextInt();【在main中】
2)暂时不需要理解
2、分支结构(下)
1)if...else if:多条路
------①语法:
if(boolean-1){
语句块1
}else if(boolean-2){
语句块2
}else if(boolean-3){
语句块3
}else{
语句块4
}
------②执行过程:
判断boolean-1,若为true则执行语句块1(结束),若为false则
再判断boolean-2,若为true则执行语句块2(结束),若为false则
再判断boolean-3,若为true则执行语句块3(结束),若为false则执行语句块4(结束)
2)说明:
------语句块1/2/3/4,必走其中之一-------------多选1
3)switch case:多条路
------①优点:效率高,结构清晰
------②缺点:只能对整数进行“相等”判断
------③break:跳出switch
------④语法:
switch(int){
case 1: //int a=1时
System.out.println(111);
break;
case 2: //int a=2时
System.out.println("222");
break;
case 3: //int a=3时
System.out.println("333");
break;<