1、if条件语句
(1)简单的if条件语句
if (age<18){
System.out.println("未成年");
}
(2)If...else条件语句
if (age<18){
System.out.println("未成年");
}
else {
System.out.println("成年");
}
(3)If...else if 多分支语句
if (age<18){
System.out.println("未成年");
}
else if (age<30){
System.out.println("青年");
}
else if (age<50){
System.out.println("中年");
}
else if (age<80){
System.out.println("老年");
}
else{
System.out.println("I Don't Know!");
}
2、switch多分支语句
switch(week){
case 0:
System.out.println("Sunday");
break; //中断
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
case 4:
System.out.println("Thursday");
break;
case 5:
System.out.println("Friday");
break;
case 6:
System.out.println("Saturday");
break;
default:
System.out.println("请输入0~6");
}
附:本课思维导图