java请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续 判断第二个字母.代码
时间: 2023-10-21 11:59:54 浏览: 34
Java基础编程:输入星期几的第一个字母来判断一下是星期几
下面是Java代码实现:
```
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入星期几的第一个字母:");
char ch = scanner.next().charAt(0);
char second = ' ';
if (ch == 'M' || ch == 'm') {
System.out.println("Monday");
} else if (ch == 'W' || ch == 'w') {
System.out.println("Wednesday");
} else if (ch == 'F' || ch == 'f') {
System.out.println("Friday");
} else if (ch == 'T' || ch == 't') {
System.out.print("请输入第二个字母:");
second = scanner.next().charAt(0);
if (second == 'u' || second == 'U') {
System.out.println("Tuesday");
} else if (second == 'h' || second == 'H') {
System.out.println("Thursday");
} else {
System.out.println("输入错误!");
}
} else if (ch == 'S' || ch == 's') {
System.out.print("请输入第二个字母:");
second = scanner.next().charAt(0);
if (second == 'a' || second == 'A') {
System.out.println("Saturday");
} else if (second == 'u' || second == 'U') {
System.out.println("Sunday");
} else {
System.out.println("输入错误!");
}
} else {
System.out.println("输入错误!");
}
}
}
```
阅读全文