Home > Java > javaTutorial > body text

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

零下一度
Release: 2017-06-25 10:30:37
Original
2472 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template