Java classic programming question 50 to 26, java programming 50
Enter the first letter of the day of the week to determine the day of the week. If the first letter is the same, continue to judge the second letter.
Public class Example26 {
Public static void main (String [] args ){
F ();
}
Public static void f (){
System. out. println ("Enter the first uppercase 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 ("the letter corresponds to Friday. "); Break;
Case 'T ':{
System. out. println ("enter the second letter of the week :");
Char ch2 = getChar ();
If (ch2 = 'U '){
System. out. println ("the letter corresponds to Tuesday. ");
} Else if (ch2 = 'H '){
System. out. println ("the letter corresponds to Thursday. ");
} Else {
System. out. println ("none! ");
}
}; Break;
Case's ':{
System. out. println ("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 ("this letter corresponds to Saturday ");
} Else {
System. out. println ("none! ");
}
}; Break;
Default:
System. out. println ("the character you entered cannot be judged !!! ");
}
}
Public static char getChar (){
@ SuppressWarnings ("resource ")
S = new partition (System. in );
String str = s. nextLine ();
Char ch = str. charAt (0 );
If (ch <'A' | ch> 'Z '){
System. out. println ("Incorrect initial letter input. Please enter it again !!! ");
Ch = getChar ();
}
Return ch;
}
}