Code written by a very serious student
Release: 2016-07-25 09:08:15
Original
791 people have browsed it
- package com.qimenguigu.l07131;
-
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
-
- /**
- * Enter the year, month, day, next|prior, if it is a correct date, calculate the previous or next day
- *
- * @author Longjie
- * @website www.qimenguigu.com
- */
- public class Title15 {
- public static void main(String[] args) throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- System.out.println("请输入年份");
- String s1 = br.readLine();
- System.out.println("请输入月份");
- String s2 = br.readLine();
- System.out.println("请输入日份");
- String s3 = br.readLine();
- int year = Integer.parseInt(s1);
- int month = Integer.parseInt(s2);
- int day = Integer.parseInt(s3);
-
- if (year >= 0 && month >= 1 && month <= 12) {
- if (month == 1 || month == 3 || month == 5 || month == 7
- || month == 8 || month == 10 || month == 12) {
- if (day >= 1 && day <= 31) {
- System.out.println("您输入的日期为:" + year + "年" + month + "月"
- + day + "日");
- if (day == 31) {
- if (month == 12)
- System.out.println("且上一天为:" + year + "年12月"
- + (day - 1) + "日" + "," + "下一天为:"
- + (year + 1) + "年1月1日");
- else
- System.out.println("且上一天为:" + year + "年" + month
- + "月" + (day - 1) + "日" + "," + "下一天为:"
- + year + "年" + (month + 1) + "月1日");
- } else if (day == 1) {
- if (month == 1)
- System.out.println("且上一天为:" + (year - 1)
- + "年12月31日" + "," + "下一天为:" + year + "年"
- + month + "月" + (day + 1) + "日");
- else if (month == 3) {
- if ((year % 4 == 0 && year % 100 != 0)
- || (year % 400 == 0))
- System.out.println("且上一天为:" + year + "年2月29日"
- + "," + "下一天为:" + year + "年" + month
- + "月" + (day + 1) + "日");
- else
- System.out.println("且上一天为:" + year + "年2月28日"
- + "," + "下一天为:" + year + "年" + month
- + "月" + (day + 1) + "日");
- } else
- System.out.println("且上一天为:" + year + "年"
- + (month - 1) + "月30日" + "," + "下一天为:"
- + year + "年" + month + "月" + (day + 1)
- + "日");
- } else
- System.out.println("且上一天为:" + year + "年" + month + "月"
- + (day - 1) + "日" + "," + "下一天为:" + year + "年"
- + month + "月" + (day + 1) + "日");
- } else
- System.out.println("您输入的日期不合法");
- } else if (month == 4 || month == 6 || month == 9 || month == 11) {
- if (day >= 1 && day <= 30) {
- System.out.println("您输入的日期为:" + year + "年" + month + "月"
- + day + "日");
- if (day == 30)
- System.out.println("且上一天为:" + year + "年" + month + "月"
- + (day - 1) + "日" + "," + "下一天为:" + year + "年"
- + (month + 1) + "月1日");
- else if (day == 1)
- System.out.println("且上一天为:" + year + "年" + (month - 1)
- + "月31日" + "," + "下一天为:" + year + "年" + month
- + (day + 1) + "日");
- else
- System.out.println("且上一天为:" + year + "年" + month + "月"
- + (day - 1) + "日" + "," + "下一天为:" + year + "年"
- + month + (day + 1) + "日");
- } else
- System.out.println("您输入的日期不合法");
- }else if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
- if (day == 29)
- System.out.println("The date you entered It is: " + year + "year" + month + "month"
- + day + "day" + "n" + "And the previous day is: " + year + "February 28th"
- + "," + "The next day is:" + year + "March 1st of the year");
- else {
- if (day == 28)
- System.out.println("The date you entered is:" + year + "Year" + month
- + "month" + day + "day" + "n" + "And the previous day is:" + year
- + "February 27th of the year" + "," + "The next day is:" + year + "February 29, year");
- else
- System.out.println("The date you entered is illegal");
- }
- }
- } else
- System.out.println("The date you entered is illegal" );
- }
- }
-
Copy code
|
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31