1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| package test01; import java.util.Scanner;
public class B1 { public static void main(String args[]) { DayandMonth ct = new DayandMonth(); ct.days(); } } class Chartype{ Boolean A; private char B; String str; Scanner sc = new Scanner(System.in); public Chartype() { A = true; } public void work(){ do { System.out.println("输入单个字符,回车退出:"); str = sc.nextLine(); if (str.equals("")) { A = false; break; } B = str.charAt(0); if (B >= 'a' && B <= 'z') { System.out.println("输入字符:" + B + "为小写字母"); }else if (B >= 'A' && B <= 'Z') { System.out.println("输入字符:" + B + "为大写字母"); }else if (B >= '0' && B <= '9') { System.out.println("输入字符:" + B + "为数字"); }else { System.out.println("输入字符:" + B + "非法字符"); } } while (A); sc.close(); } } class DayandMonth{ private int month,year; Scanner sc = new Scanner(System.in); private String str1; boolean choose = true; public void days() { do { System.out.println("请输入:"); str1 = sc.nextLine(); if (str1.equals("")) { choose = false; break; } if (month == 2) { if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) { System.out.println(year + "是闰年" + month + "有29天"); }else System.out.println(year + "不是闰年" + month + "有28天"); } else if (month >= 1 && month <= 8) { System.out.println(year + "年 " + month + "月有 " + (30 + month % 2) + "天"); }else System.out.println(year + "年 " + month + "月有 " + (31 - month % 2) + "天"); } while (choose); sc.close(); } }
|