用Java编写程序,要求输入1~7的某个数,输出表示一星期中相应的某一天的 单词:Monday、Tuesday等,用switch语句实现。
时间: 2023-04-04 14:00:51 浏览: 125
可以回答这个问题。以下是Java代码:
```
import java.util.Scanner;
public class Weekday {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入1~7的某个数:");
int day = input.nextInt();
String weekday;
switch (day) {
case 1:
weekday = "Monday";
break;
case 2:
weekday = "Tuesday";
break;
case 3:
weekday = "Wednesday";
break;
case 4:
weekday = "Thursday";
break;
case 5:
weekday = "Friday";
break;
case 6:
weekday = "Saturday";
break;
case 7:
weekday = "Sunday";
break;
default:
weekday = "输入错误";
break;
}
System.out.println("星期" + day + "是" + weekday);
}
}
```
阅读全文