IF..else与switch语句记录

IF..else与switch语句记录

import java.util.Scanner;

public class IfDemo03 {
    public static void main(String[] args) {
        //考试分数大于60就是及格,小于60分就不及格
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入成绩:");
        int score = scanner.nextInt();

        if (score==100){
            System.out.println("恭喜满分");
        }else if (score<100 && score>=90){
            System.out.println("A级");
        }else if (score<90 && score>=80){
            System.out.println("B级");
        }else if (score<80 && score>=70){
            System.out.println("C级");
        }else if (score<70 && score>=60){
            System.out.println("D级");
        }else if (score<60 && score>=0){
            System.out.println("不及格");
        }else {
            System.out.println("成绩不合法");
        }

        scanner.close();
    }
}

public class SwitchDemo01 {
    public static void main(String[] args) {
        //case穿透    //switch 匹配一个具体的值
        char grade = 'A';

        switch (grade){
            case 'A':
                System.out.println("优秀");
                break; //可选
            case 'B':
                System.out.println("良好");
                break; //可选
            case 'C':
                System.out.println("及格");
                break; //可选
            case 'D':
                System.out.println("再接再厉");
                break; //可选
            case 'E':
                System.out.println("挂科");
                break; //可选
            default:
                System.out.println("未知等级");
        }
    }
}

public class SwitchDemo02 {
    public static void main(String[] args) {
        String name = "啊卢";
        //JDK7的新特性,表达式结果可以是字符串!!!
        //字符的本质还是数字

        //反编译   java---class(字节码文件)---反编译(IDEA)

        switch (name){
            case "小卢":
                System.out.println("小卢");
                break;
            case "啊卢":
                System.out.println("啊卢");
                break;
            default:
                System.out.println("弄啥嘞!");
        }
    }
}
posted @ 2020-07-06 15:30  小卢传  阅读(109)  评论(0编辑  收藏  举报