顺序结构


 

 1 package Struct;
 2 
 3 import java.util.Scanner;
 4 
 5 public class IfDemo1 {
 6     public static void main(String[] args) {
 7         Scanner scanner=new Scanner(System.in);
 8 
 9         System.out.println("请输入内容:");
10        String s= scanner.nextLine();
11 
12        //equals :   判断字符串是否相等
13        if (s.equals("hello")){
14            System.out.println(s);
15        }
16         System.out.println("End");
17         scanner.close();
18     }
19 }
 1 package Struct;
 2 
 3 import java.util.Scanner;
 4 
 5 public class IfDemo2 {
 6     public static void main(String[] args) {
 7         //考试分数大于60分就是及格,小于60分就是不及格
 8         Scanner scanner=new Scanner(System.in);
 9 
10         System.out.println("请输入成绩:");
11 
12         int score = scanner.nextInt();
13         if (score>60){
14             System.out.println("及格");
15         }else{
16             System.out.println("不及格");
17         }
18 
19         scanner.close();
20     }
21 }
 1 package Struct;
 2 
 3 import java.util.Scanner;
 4 
 5 public class IfDemo4 {
 6     public static void main(String[] args) {
 7 
 8         //考试分数大于60分就是及格,小于60分就是不及格
 9         Scanner scanner=new Scanner(System.in);
10         /*
11         if 语句至多有一个else语句,else语句在所有的else if语句之后。
12         if 语句可以有若干个else if语句,它们必须在else 语句之前。
13         一旦 其中一个else if  语句检测为true,其他的else if以及else 语句都将跳过执行
14          */
15 
16         System.out.println("请输入成绩:");
17         int score = scanner.nextInt();
18 
19         if (score==100){
20             System.out.println("恭喜满分");
21         }else if (score<100&&score>=90){
22             System.out.println("A级");
23         }else if (score<90&&score>=80){
24             System.out.println("B级");
25         }else if (score<80&&score>=70){
26             System.out.println("C级");
27         }else if (score<70&&score>=60){
28             System.out.println("D级");
29         } else if (score<60&&score>=0){
30             System.out.println("不及格");
31         }else{
32             System.out.println("成绩不合格");
33         }
34 
35 
36         scanner.close();
37     }
38 }

 

posted on 2021-04-30 18:27  帆吖  阅读(40)  评论(0)    收藏  举报