Home  >  Article  >  Java  >  Java classic programming question--determine the day of the week

Java classic programming question--determine the day of the week

零下一度
零下一度Original
2017-06-25 10:30:372477browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn