zoukankan      html  css  js  c++  java
  • Java经典编程题50道之二十六

    请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母。

    public class Example26 {
        public static void main(String[] args) {
            f();
        }

        public static void f() {
            System.out.println("请输入星期的第一个大写字母:");
            char ch = getChar();
            switch (ch) {
            case 'M':
                System.out.println("该字母对应的是Monday。");break;
            case 'W':
                System.out.println("该字母对应的是Wednesday。");break;
            case 'F':
                System.out.println("该字母对应的是Friday。");break;
            case 'T': {
                System.out.println("请输入星期的第二个字母:");
                char ch2 = getChar();
                if (ch2 == 'U') {
                    System.out.println("该字母对应的是Tuesday。");
                } else if (ch2 == 'H') {
                    System.out.println("该字母对应的是Thursday。");
                } else {
                    System.out.println("无此写法!");
                }
            };break;
            case 'S': {
                System.out.println("请输入星期的第二个字母:");
                char ch2 = getChar();
                if (ch2 == 'U') {
                    System.out.println("该字母对应的是Sunday");
                } else if (ch2 == 'A') {
                    System.out.println("该字母对应的是Saturday");
                } else {
                    System.out.println("无此写法!");
                }
            };break;
            default:
                System.out.println("无法判断你输入的字符!!!");
            }
        }
        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("首字母输入错误,请重新输入!!!");
                ch = getChar();
            }
            return ch;
        }
    }

  • 相关阅读:
    Es索引优化
    Echarts-JAVA
    黑客容易攻击的端口
    基于流数据挖掘的网络流量异常检测及分析研究
    大数据可视化分析-绿盟
    Cron
    spring mvc 使用及json 日期转换解决方案
    PIXLCLOUND
    Moloch
    MySQL JDBC的setFetchSize
  • 原文地址:https://www.cnblogs.com/qubo520/p/6950795.html
Copyright © 2011-2022 走看看