java实现根据输入的英文单词Monday、Tuesday、Wednesday、Thursday、Friday、Saturday、Sunday;输出对应的星期一、星期二、星期三、星期四、星期五、星期六、星期天;当输入其他英文单词则提示:输入有误!。
时间: 2023-09-16 17:10:20 浏览: 493
您好,这是一个Java实现输出星期的问题,我可以为您提供解决方法。
您可以使用Java中的switch语句,根据输入的英文单词输出对应的星期。以下是完整的Java代码:
```
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入英文单词:");
String input = scanner.nextLine();
switch (input.toLowerCase()) {
case "monday":
System.out.println("星期一");
break;
case "tuesday":
System.out.println("星期二");
break;
case "wednesday":
System.out.println("星期三");
break;
case "thursday":
System.out.println("星期四");
break;
case "friday":
System.out.println("星期五");
break;
case "saturday":
System.out.println("星期六");
break;
case "sunday":
System.out.println("星期天");
break;
default:
System.out.println("输入有误!");
break;
}
}
}
```
代码运行后,您可以输入Monday、Tuesday、Wednesday、Thursday、Friday、Saturday、Sunday中的任意一个单词,程序会输出对应的星期;输入其他单词会输出提示信息"输入有误!"。
希望这个回答可以帮到您,如果您有其他问题,欢迎随时提问。
阅读全文
相关推荐


















