用键盘输入一位整数,当输入1~7时,显示对应英文星期名称缩写,ଠ1表示MON 2表示TUE……

2024-11-25 23:25:28
推荐回答(4个)
回答1:

//我稍微修改了一下你的代码,你试试看行不行
import java.util.Scanner;

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("请输入:");
Integer num = in.nextInt();
String day = "";
switch (num) {
case 1:
day = "MON";
break;
case 2:
day = "TUE";
break;
case 3:
day = "WED";
break;
case 4:
day = "THU";
break;
case 5:
day = "FRI";
break;
case 6:
day = "SAT";
break;
case 7:
day = "SUN";
break;
default:
System.out.println("输入有误!");
break;

}
System.out.print(day);

}

回答2:

空值“”不能转化为Integer类型。加个判断。为空返回,或者为空让他等于0.

回答3:

Scanner in=new Scanner(System.in);
int num=in.nextInt();

回答4:

双重for循环更简单点