Java Classic Programming Question 50-way 26

Source: Internet
Author: User

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

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.