Please enter the first letter of the day of the week to determine the day of the week, if the first letter, then continue to judge 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 ("The letter corresponds to the Monday. "); break;
Case ' W ':
SYSTEM.OUT.PRINTLN ("The letter corresponds to the Wednesday. "); break;
Case ' F ':
SYSTEM.OUT.PRINTLN ("The letter corresponds to the Friday. "); break;
Case ' T ': {
System.out.println ("Please enter the second letter of the Week:");
Char CH2 = GetChar ();
if (CH2 = = ' U ') {
SYSTEM.OUT.PRINTLN ("The letter corresponds to the Tuesday. ");
} else if (CH2 = = ' H ') {
SYSTEM.OUT.PRINTLN ("The letter corresponds to the Thursday. ");
} else {
System.out.println ("No such wording!") ");
}
};break;
Case ' S ': {
System.out.println ("Please enter the second letter of the Week:");
Char CH2 = GetChar ();
if (CH2 = = ' U ') {
SYSTEM.OUT.PRINTLN ("The letter corresponds to Sunday");
} else if (CH2 = = ' A ') {
SYSTEM.OUT.PRINTLN ("The letter corresponds to Saturday");
} else {
System.out.println ("No such wording!") ");
}
};break;
Default
System.out.println ("Unable to judge the character you entered!!! ");
}
}
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 ("Initial input error, please re-enter!!!" ");
ch = GetChar ();
}
return ch;
}
}
Java Classic Programming Question 50-way 26