Please enter the first letter of the day of the week to determine the day of the week. If the first letters are the same, continue to determine the second letter.
public class Example26 {
public static void main(String[] args) {
f();
}
public static void f() {
System.out.println("Please enter the first capital letter of the week: ");
char ch = getChar();
switch (ch) {
case 'M':
System.out.println("This letter corresponds to Monday.");break;
case 'W':
System.out.println("This letter corresponds to Wednesday.");break;
case 'F': System.out.println("This letter corresponds to Friday.");break; The second letter of the week: ");
char ch2 = getChar();
if (ch2 == 'U') {
System.out.println("This letter corresponds to Tuesday. ");
} else if (ch2 == 'H') {
System.out.println("This letter corresponds to Thursday "); .println("There is no such way of writing!");
}
};break;
case 'S': {
System.out.println("Please enter the second letter of the week: ");
char ch2 = getChar();
if (ch2 == 'U') {
System.out.println("This letter corresponds to Sunday");
} else if (ch2 == 'A') {
System.out.println("This letter corresponds to Saturday");
");
}
;break;
## public static char getChar() {
@SuppressWarnings("resource")
Scanner s = new Scanner(System.in);
String str = s.nextLine();
char ch = str.charAt(0);
if (ch < 'A' || ch > 'Z') {
System.out.println("The first letter was entered incorrectly, please re-enter!!! ");
ch = getChar();
}
return ch;
}
}
The above is the detailed content of Java classic programming question--determine the day of the week. For more information, please follow other related articles on the PHP Chinese website!