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("输入有误!");

    }

    }

    }

  • 相关阅读:
    【原创】go语言学习(十六)接口
    【原创】go语言学习(十五)IO操作2
    【原创】go语言学习(十四)IO操作1
    【原创】go语言学习(十三)struct介绍2
    【原创】go语言学习(十二)struct介绍1
    【原创】go语言学习(十一)package简介
    【原创】sed正则表达式替换
    【原创】go语言学习(十)Map类型
    【原创】go语言学习(九)指针类型
    【原创】go语言学习(八)切片
  • 原文地址:https://www.cnblogs.com/zhuozige/p/12358695.html
Copyright © 2011-2022 走看看