1 package FlowControl;
2
3 import java.util.Scanner;
4
5 public class Demo05If {
6 public static void main(String[] args) {
7 Scanner s=new Scanner(System.in);
8 System.out.println("请输入一个分数");
9 int score=s.nextInt();
10 // if单选择结构
11 if(score==100){
12 System.out.println("周硕是个大美女");
13 }
14
15 // if双选择结构
16 if (score<60){
17 System.out.println("不及格");
18 }else{
19 System.out.println("及格了");
20 }
21
22 // if多选择结构
23 if (score==100){
24 System.out.println("满分,牛逼");
25 }else if (score<100&&score>80){
26 System.out.println("也可以了");
27 }else if(score<=80&&score>60){
28 System.out.println("再接再厉");
29 }else if(score<=60&&score>0){
30 System.out.println("挂了");
31 }else{
32 System.out.println("请输入1-100的数字");
33 }
34
35 //嵌套的if结构
36 if (score<70){
37 if (score>60){
38 System.out.println("挂科边缘");
39 }else{
40 System.out.println("废了");
41 }
42 }
43
44 s.close();
45 }
46 }
上面是if,下面是switch
1 package FlowControl;
2
3 public class Demo06switch {
4 public static void main(String[] args) {
5 // Switch多选择结构 从java7开始,支持字符串String类型了
6 String score="A";
7 switch (score){
8 case "A":
9 System.out.println("A哟~");
10 break;
11 case "B":
12 System.out.println("B哟~");
13 break;
14 default:{
15 System.out.println("无");
16 }
17 }
18 }
19 }