switch(表达式){
    case 表达1:
    语句1:
    break;
    case 表达2:
    语句2:
    break;
    ……
    default:
    语句
    }

    1. public static void main(String[] args) {
    2. Scanner sc = new Scanner(System.in);
    3. System.out.println("请输入你的年级");
    4. int grade = sc.nextInt();
    5. switch(grade){
    6. case 1:
    7. System.out.println("一年级");
    8. break;
    9. case 2:
    10. System.out.println("二年级");
    11. break;
    12. case 3:
    13. System.out.println("三年级");
    14. break;
    15. case 4:
    16. System.out.println("四年级");
    17. break;
    18. default:
    19. System.out.println("社会人");
    20. }
    21. }