Java classic programming question 50 to 26, java programming 50

Source: Internet
Author: User
Tags uppercase letter

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;
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.