当前位置:Gxlcms > PHP教程 > 一位态度非常认真的学生写的代码

一位态度非常认真的学生写的代码

时间:2021-07-01 10:21:17 帮助过:6人阅读

<无详细内容>
  1. package com.qimenguigu.l07131;
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. /**
  6. * 输入年,月,日,next|prior,如果是一个正确的日期,算出上一天或下一天
  7. *
  8. * @author Longjie
  9. * @website www.qimenguigu.com
  10. */
  11. public class Title15 {
  12. public static void main(String[] args) throws IOException {
  13. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  14. System.out.println("请输入年份");
  15. String s1 = br.readLine();
  16. System.out.println("请输入月份");
  17. String s2 = br.readLine();
  18. System.out.println("请输入日份");
  19. String s3 = br.readLine();
  20. int year = Integer.parseInt(s1);
  21. int month = Integer.parseInt(s2);
  22. int day = Integer.parseInt(s3);
  23. if (year >= 0 && month >= 1 && month <= 12) {
  24. if (month == 1 || month == 3 || month == 5 || month == 7
  25. || month == 8 || month == 10 || month == 12) {
  26. if (day >= 1 && day <= 31) {
  27. System.out.println("您输入的日期为:" + year + "年" + month + "月"
  28. + day + "日");
  29. if (day == 31) {
  30. if (month == 12)
  31. System.out.println("且上一天为:" + year + "年12月"
  32. + (day - 1) + "日" + "," + "下一天为:"
  33. + (year + 1) + "年1月1日");
  34. else
  35. System.out.println("且上一天为:" + year + "年" + month
  36. + "月" + (day - 1) + "日" + "," + "下一天为:"
  37. + year + "年" + (month + 1) + "月1日");
  38. } else if (day == 1) {
  39. if (month == 1)
  40. System.out.println("且上一天为:" + (year - 1)
  41. + "年12月31日" + "," + "下一天为:" + year + "年"
  42. + month + "月" + (day + 1) + "日");
  43. else if (month == 3) {
  44. if ((year % 4 == 0 && year % 100 != 0)
  45. || (year % 400 == 0))
  46. System.out.println("且上一天为:" + year + "年2月29日"
  47. + "," + "下一天为:" + year + "年" + month
  48. + "月" + (day + 1) + "日");
  49. else
  50. System.out.println("且上一天为:" + year + "年2月28日"
  51. + "," + "下一天为:" + year + "年" + month
  52. + "月" + (day + 1) + "日");
  53. } else
  54. System.out.println("且上一天为:" + year + "年"
  55. + (month - 1) + "月30日" + "," + "下一天为:"
  56. + year + "年" + month + "月" + (day + 1)
  57. + "日");
  58. } else
  59. System.out.println("且上一天为:" + year + "年" + month + "月"
  60. + (day - 1) + "日" + "," + "下一天为:" + year + "年"
  61. + month + "月" + (day + 1) + "日");
  62. } else
  63. System.out.println("您输入的日期不合法");
  64. } else if (month == 4 || month == 6 || month == 9 || month == 11) {
  65. if (day >= 1 && day <= 30) {
  66. System.out.println("您输入的日期为:" + year + "年" + month + "月"
  67. + day + "日");
  68. if (day == 30)
  69. System.out.println("且上一天为:" + year + "年" + month + "月"
  70. + (day - 1) + "日" + "," + "下一天为:" + year + "年"
  71. + (month + 1) + "月1日");
  72. else if (day == 1)
  73. System.out.println("且上一天为:" + year + "年" + (month - 1)
  74. + "月31日" + "," + "下一天为:" + year + "年" + month
  75. + (day + 1) + "日");
  76. else
  77. System.out.println("且上一天为:" + year + "年" + month + "月"
  78. + (day - 1) + "日" + "," + "下一天为:" + year + "年"
  79. + month + (day + 1) + "日");
  80. } else
  81. System.out.println("您输入的日期不合法");
  82. } else if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
  83. if (day == 29)
  84. System.out.println("您输入的日期为:" + year + "年" + month + "月"
  85. + day + "日" + "\n" + "且上一天为:" + year + "年2月28日"
  86. + "," + "下一天为:" + year + "年3月1日");
  87. else {
  88. if (day == 28)
  89. System.out.println("您输入的日期为:" + year + "年" + month
  90. + "月" + day + "日" + "\n" + "且上一天为:" + year
  91. + "年2月27日" + "," + "下一天为:" + year + "年2月29日");
  92. else
  93. System.out.println("您输入的日期不合法");
  94. }
  95. }
  96. } else
  97. System.out.println("您输入的日期不合法");
  98. }
  99. }

人气教程排行