• JAVA 基础编程练习题26 【程序 26 求星期】


    26 【程序 26 求星期】

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

    程序分析:用情况语句比较好,如果第一个字母一样,则判断用情况语句或 if 语句判断第二个字母。

    package cskaoyan;
    
    public class cskaoyan26 {
    	@org.junit.Test
    	public void days() {
    		java.util.Scanner in = new java.util.Scanner(System.in);
    		System.out.print("please input:");
    		char ch = in.next().charAt(0);
    
    		if (ch == 'M' || ch == 'm') {
    			System.out.println("Monday");
    		} else if (ch == 'T' || ch == 't') {
    			System.out.print("please input second letter:");
    			ch = in.next().charAt(0);
    			if (ch == 'U' || ch == 'u') {
    				System.out.println("Tuesday");
    			} else if (ch == 'H' || ch == 'h') {
    				System.out.println("Thursday");
    			} else {
    				System.out.println("data error");
    			}
    		} else if (ch == 'W' || ch == 'w') {
    			System.out.println("Wednesday");
    		} else if (ch == 'F' || ch == 'f') {
    			System.out.println("Friday");
    		} else if (ch == 'S' || ch == 's') {
    			System.out.print("please input second letter:");
    			ch = in.next().charAt(0);
    			if (ch == 'A' || ch == 'a') {
    				System.out.println("Saturday");
    			} else if (ch == 'U' || ch == 'u') {
    				System.out.println("Sunday");
    			} else {
    				System.out.println("data error");
    			}
    		} else {
    			System.out.println("data error");
    		}
    
    		in.close();
    	}
    }
    
  • 相关阅读:
    codeforce 272B Dima and Sequence
    Codeforce 270D Greenhouse Effect
    codeforce 270C Magical Boxes
    codeforce 270B Multithreading
    图论--Dijkstra算法总结
    图论--(技巧)超级源点与超级汇点
    图论--Floyd总结
    ZOJ 3932 Handshakes
    ZOJ 3932 Deque and Balls
    ZOJ 3927 Programming Ability Test
  • 原文地址:https://www.cnblogs.com/denggelin/p/11397728.html
Copyright © 2020-2023  润新知