zoukankan      html  css  js  c++  java
  • Java经典习题26

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

    import java.util.*;

    public class Class26 {

    public static void main(String[] args) {
    System.out.println("输入第一个字母:");
    Scanner sc1 = new Scanner(System.in);
    String s1 = sc1.nextLine();
    char ch1 = s1.charAt(0);
    if(ch1 < 'A' || ch1 > 'Z' || ch1 < 'a' || ch1 > 'z'){
    //System.out.println("输入有误!");
    }
    switch(ch1){
    case 'M':
    System.out.println("星期一");
    break;
    case 'm':
    System.out.println("星期一");
    break;
    case 'W':
    System.out.println("星期三");
    break;
    case 'w':
    System.out.println("星期三");
    break;
    case 'F':
    System.out.println("星期五");
    break;
    case 'f':
    System.out.println("星期五");
    break;
    case 'T':
    System.out.println("请输入第二个字母:");
    Scanner sc2 = new Scanner(System.in);
    String s2 = sc2.nextLine();
    char ch2 = s2.charAt(0);
    if(ch2 < 'A' || ch2 > 'Z' || ch2 < 'a' || ch2 > 'z'){
    //System.out.println("输入有误!");
    }else if(ch2 == 'U'){
    System.out.println("星期二");
    }else if(ch2 == 'H'){
    System.out.println("星期四");
    }else{
    System.out.println("输入有误!");
    }
    break;
    case 't':
    System.out.println("请输入第二个字母:");
    Scanner sc3 = new Scanner(System.in);
    String s3 = sc3.nextLine();
    char ch3 = s3.charAt(0);
    if(ch3 < 'A' || ch3 > 'Z' || ch3 < 'a' || ch3 > 'z'){
    //System.out.println("输入有误!");
    }else if(ch3 == 'u'){
    System.out.println("星期二");
    }else if(ch3 == 'h'){
    System.out.println("星期四");
    }else{
    System.out.println("输入有误!");
    }
    break;
    case 'S':
    System.out.println("请输入第二个字母:");
    Scanner sc4 = new Scanner(System.in);
    String s4 = sc4.nextLine();
    char ch4 = s4.charAt(0);
    if(ch4 < 'A' || ch4 > 'Z' || ch4 < 'a' || ch4 > 'z'){
    //System.out.println("输入有误!");
    }else if(ch4 == 'A'){
    System.out.println("星期六");
    }else if(ch4 == 'U'){
    System.out.println("星期日");
    }else{
    System.out.println("输入有误!");
    }
    break;
    case 's':
    System.out.println("请输入第二个字母:");
    Scanner sc5 = new Scanner(System.in);
    String s5 = sc5.nextLine();
    char ch5 = s5.charAt(0);
    if(ch5 < 'A' || ch5 > 'Z' || ch5 < 'a' || ch5 > 'z'){
    //System.out.println("输入有误!");
    }else if(ch5 == 'u'){
    System.out.println("星期六");
    }else if(ch5 == 'h'){
    System.out.println("星期日");
    }else{
    System.out.println("输入有误!");
    }
    break;
    default:
    System.out.println("输入有误!");

    }

    }

    }

  • 相关阅读:
    Sales Portal遇到问题及解决
    LYOA 遇到的问题及解决方案
    ERS遇到的问题及solution
    ehr遇到问题及解决方法
    dropdownlist中的Checkbox,可控制是否postback
    javascirpt
    【spring boot】idea下springboot打包成jar包和war包,并且可以在外部tomcat下运行访问到(转)
    SpringBoot2.1整合finereport10(帆软报表)
    Windows下MyCat配置MySql读写分离
    Windows下MySQL主从同步
  • 原文地址:https://www.cnblogs.com/zhuozige/p/12358695.html
Copyright © 2011-2022 走看看