Switch
switch语句
swit语句中的变量类型可以是:
1.byte、short、int、char
2.switch支持字符串String类型
3.case标签必须为字符串常量或字面量
语句:
switch(expression){
case value:
1 package com.stx.zx; 2 //case穿透 break跳出循环 3 //switch匹配一个具体的值 4 public class Switch01 { 5 public static void main ( String[] args ) { 6 char grade='A'; 7 switch (grade){ 8 case'A': 9 System.out.println("优秀"); 10 break; //可选 11 case'B': 12 System.out.println("良好"); 13 break; 14 case'C': 15 System.out.println("合格"); 16 break; 17 case'D': 18 System.out.println("不合格"); 19 break; 20 default: 21 System.out.println("输入格式不符合规范"); 22 } 23 } 24 }

浙公网安备 33010602011771号