用java输出一个从键盘输入0-6之间的整数,输出对应的星期几的中文或英文字符串。
时间: 2024-05-25 17:18:47 浏览: 89
import java.util.Scanner;
public class Weekday {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入0-6之间的整数:");
int num = scanner.nextInt();
String weekday = "";
switch (num) {
case 0:
weekday = "Sunday";
break;
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;
default:
System.out.println("输入错误!");
return;
}
System.out.println("星期" + weekday);
}
}
阅读全文