/* switch格式: switch(表达式) { case 值1: 语句体1; break; case 值2: 语句体2; break; default: 语句体n+1; break; } */ import java.util.Scanner; class SwitchDemo { public static void main(String [] args) { Scanner sc = new Scanner(System.in); int week = sc.nextInt(); switch(week) { case 1: //case后面只能是常量 System.out.println("星期一"); break; case 2: System.out.println("星期二"); break; case 3: System.out.println("星期3"); break; case 4: System.out.println("星期4"); break; case 5: System.out.println("星期5"); break; default : System.out.println("输入有误"); break; } } }