• java【第三课 条件语句】


    一.java条件语句

    import java.util.Scanner;  //导入扫描仪
    
    public class demo{
         public static void main(String[] args){
             Scanner data = new Scanner(System.in);
             
             System.out.println("请输入成绩:");
             int grade = data.nextInt();
    
             if(grade>60){
                System.out.println("恭喜进阶!");
             }
             else{
                 System.out.println("还是继续学习!");
             }
             System.out.println("测试阶段");
    
       
        }
    }

    二.switch语句

      

    import java.util.Scanner;  //导入扫描仪
    
    
    public class demo{
         public static void main(String[] args){
             Scanner data = new Scanner(System.in);
             
             System.out.println("请输入成绩:");
             int grade = data.nextInt();
             char rating = ' ';
             //成绩分支
             if(grade>0 && grade<45){
                   rating = 'H';
             }
             else if(grade > 45 && grade <60)
             {
                     rating = 'G';
             }
             else if(grade >60 && grade <75){
                  rating = 'F';
             }
             else if(grade >75 && grade <90){
                  rating = 'E';
             }
             else if(grade >90 && grade <105){
                  rating = 'D';
             }
             else if(grade >105 && grade <120)
             {
                 rating = 'C';
             }
             else if(grade >120 && grade <135){
                 rating = 'B';
             }
             else{
                 rating = 'A';
             }
    
             //匹配等级
             switch(rating){
                 case 'A':
                     System.out.println("等级A");
                     break;
                 case 'B':
                     System.out.println("等级B");
                     break;
                 case 'C':
                      System.out.println("等级C");
                      break;
                 case 'D':
                      System.out.println("等级D");
                      break;
                 case 'E':
                      System.out.println("等级E");
                      break;
                 case 'F':
                      System.out.println("等级F");
                      break;
                 case 'G':
                      System.out.println("等级G");
                      break;
                 case 'H':
                      System.out.println("等级H");
                      break;
    
             }
            
              System.out.println("测试完成!");
       
        }
    }

    想要知道逻辑步骤:https://jingyan.baidu.com/article/ea24bc39473ff19b62b331b1.html

  • 相关阅读:
    Java异常超详细总结
    ArrayList去除集合中字符串的重复值
    scrum项目冲刺_day09
    scrum项目冲刺_day08
    scrum项目冲刺_day07
    scrum项目冲刺_day06
    scrum项目冲刺_day05
    scrum项目冲刺_day04
    scrum项目冲刺_day03
    scrum项目冲刺_day02
  • 原文地址:https://www.cnblogs.com/Crown-V/p/12367044.html
Copyright © 2020-2023  润新知