编写程序,从键盘接收整数参数。如果该数为1-7,打印对应的星期值,否则打印“非法参数”。
作者:互联网
import java.util.Scanner;
class Exer1 {
public static void main(String[] args) {
Scanner scan = new Scanner (System.in);
System.out.println("请输入星期值:");
int week = scan.nextInt();
switch (week){
case 1:
System.out.println("星期一:Monday");
break;
case 2:
System.out.println("星期二:Tuesday");
break;
case 3:
System.out.println("星期三:Wednesday");
break;
case 4:
System.out.println("星期四:Thursday");
break;
case 5:
System.out.println("星期五:Friday");
break;
case 6:
System.out.println("星期六:Saturday");
break;
case 7:
System.out.println("星期日:Sunday");
break;
default:
System.out.println("非法星期值");
break;
}
}
}
标签:case,Scanner,打印,System,break,参数,println,该数,out 来源: https://blog.csdn.net/qq_47896523/article/details/122611392