- package com.qimenguigu.l07131;
-
- 導入java.io.BufferedReader;
- 導入java.io.IOException導入java.io.BufferedReader;
- 導入java.io.IOException InputStreamReader;
-
- /**
- * 輸入年,月,日,next|prior,如果是正確的日期,算出上一天或下一天
- *
- * @author Longjie
- * @website www.qimenguigu.com
- */
- public class Title15 {
- public static void main(String[] args) throws IOException {
- BufferedReader br = new Buffered (System.in));
- System.out.println("請輸入年份");
- String s1 = br.readLine();
- System.out.println("請輸入年份") ;
- String s2 = br.readLine();
- System.out.println("請輸入日份");
- String s3 = br.readLine();
- intyear = Integer. parseInt (s1);
- int 月份= Integer.parseInt(s2);
- int day = Integer.parseInt(s3);
-
- if (年>= 0 && 月>= 1 && 月 if (月== 1 || 月== 3 || 月== 5 || 月== 7
- || 月== 8 || 月== 10 || 月= = 12) {
- if (day >= 1 && day System.out.println("您輸入的日期為:" + 年+ "年" +月+ "月"
- + 日+ "日");
- if (day == 31) {
- if (month == 12)
- System.out.println("且上一天為:" + 年+ "年12月"
- + (day - 1) + "日" + "," + "下一天為:"
- + (year + 1) + "年1月1日");
- else
- System.out.println("且上一天為:" + 年+ "年" + 月
- + "月" + (day - 1) + "日" + "," + "下一天為:"
- + 年+ "年" + (月+ 1) + "月1 日");
- } else if (day == 1) {
- if (月== 1)
- System.out.println("且上一天為:" + (year - 1)
- + "年12月31日" + "," + "下一天為:" + 年+ "年"
- + 月+ "月" + (日+ 1) + "日");
- else if (月== 3) {
- if ((年% 4 == 0 && 年% 100 ! = 0)
- || (year % 400 == 0))
- System.out.println("且上一天為:" + Year + "年2月29日"
- + "," + "下日為:" +年+ "年" + 月
- + "月" + (日+ 1) + "日");
- else
- System.out.println("且上一天為:" + 年+ "年2月28日"
- + "," + "下一天為:" + 年+ "年" + 月
- + "月" + (日+ 1) + "日");
- } else
- System.out.println("且上一天為:" + 年+ "年"
- + (月- 1) + "月30日" + ", " + "下一天為:"
- + 年+ "年" + 月+ "月" + (日+ 1)
- + "日");
- } else
- System.out. println("且上一天為: " + 年+ "年" + 月+ "月"
- + (日- 1) + "日" + "," + "下一天為:" + 年+ "年"
- + 月+ "月" + (day + 1) + "日");
- } else
- System.out.println("您輸入的日期不合法");
- } else if (month == 4 | | 月== 6 || 月== 9 || 月== 11) {
- if (day >= 1 && day System.out. println("您輸入的日期為:" + 年+ "年" + 月+ "月"
- + day + "日");
- if (day == 30)
- System.out. println("且上一天為:" + 年+ "年" + 月+ "月"
- + (day - 1) + "日" + "," + "下一天為:" + 年+ "年"
- + (月+ 1) + "月1日");
- else if (day == 1)
- System.out.println("且上一天為:" + Year + "年" + (month - 1 )
- + "月31日" + "," + "下一天為:" + 年+ "年" + 月
- + (日+ 1) + "日");
- else
- System.out.println("且上一天為:" + 年+ "年" + 月+ "月"
- + (day - 1) + "日" + "," + "下日為:" + 年+ "年"
- + 月+ (day + 1) + "日");
- } else
- System.out.println("您輸入的日期不合法");
- }else if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
- if (day == 29)
- System.out.println("您輸入的日期為:" + year + "年" + month + "月"
- + day + "日" + "n" + "且上一天為:" + year + "年2月28日"
- + "," + "下一天為:" + year + "年3月1日");
- else {
- if (day == 28)
- System.out.println( "您輸入的日期為:" + year + "年" + month
- + "月" + day + "日" + "n" + "且上一天為:" + year
- + "年2月27日" + "," + "下一天為:" + year + "年2月29日");
- else
- System.out.println("您輸入的日期不合法");
- }
- }
- } else
- System.out.println("您輸入的日期不合法");
- }
- }
-
複製程式碼
|