/*switch语句格式:
switch(表达式) {
case 值1:
语句体1;
break;
case 值2:
语句体2;
break;
...
default:
语句体n+1;
break;
}
*/
import java.util.Scanner;
class Switch{
public static void main(String[] args){
//创建键盘录入
Scanner sc = new Scanner(System.in);
//控制键盘录入数据
System.out.println("请输入一个数据(1-7):");
int week = sc.nextInt();
//Switch语句判断
switch(week){
case 1:
System.out.println("星期一");
break;
case 2:
System.out.println("星期二");
break;
case 3:
System.out.println("星期三");
break;
case 4:
System.out.println("星期四");
break;
case 5:
System.out.println("星期五");
break;
case 6:
System.out.println("星期六");
break;
case 7:
System.out.println("星期天");
break;
}
}
} |
|