首頁  >  文章  >  後端開發  >  一位態度非常認真的學生寫的程式碼

一位態度非常認真的學生寫的程式碼

WBOY
WBOY原創
2016-07-25 09:08:15754瀏覽
  1. package com.qimenguigu.l07131;
  2. 導入java.io.BufferedReader;
  3. 導入java.io.IOException導入java.io.BufferedReader;
  4. 導入java.io.IOException 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 Buffered (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. intyear = Integer. parseInt (s1);
  21. int 月份= Integer.parseInt(s2);
  22. int day = Integer.parseInt(s3);
  23. if (年>= 0 && 月>= 1 && 月 if (月== 1 || 月== 3 || 月== 5 || 月== 7
  24. || 月== 8 || 月== 10 || 月= = 12) {
  25. if (day >= 1 && day System.out.println("您輸入的日期為:" + 年+ "年" +月+ "月"
  26. + 日+ "日");
  27. if (day == 31) {
  28. if (month == 12)
  29. System.out.println("且上一天為:" + 年+ "年12月"
  30. + (day - 1) + "日" + "," + "下一天為:"
  31. + (year + 1) + "年1月1日");
  32. else
  33. System.out.println("且上一天為:" + 年+ "年" + 月
  34. + "月" + (day - 1) + "日" + "," + "下一天為:"
  35. + 年+ "年" + (月+ 1) + "月1 日");
  36. } else if (day == 1) {
  37. if (月== 1)
  38. System.out.println("且上一天為:" + (year - 1)
  39. + "年12月31日" + "," + "下一天為:" + 年+ "年"
  40. + 月+ "月" + (日+ 1) + "日");
  41. else if (月== 3) {
  42. if ((年% 4 == 0 && 年% 100 ! = 0)
  43. || (year % 400 == 0))
  44. System.out.println("且上一天為:" + Year + "年2月29日"
  45. + "," + "下日為:" +年+ "年" + 月
  46. + "月" + (日+ 1) + "日");
  47. else
  48. System.out.println("且上一天為:" + 年+ "年2月28日"
  49. + "," + "下一天為:" + 年+ "年" + 月
  50. + "月" + (日+ 1) + "日");
  51. } else
  52. System.out.println("且上一天為:" + 年+ "年"
  53. + (月- 1) + "月30日" + ", " + "下一天為:"
  54. + 年+ "年" + 月+ "月" + (日+ 1)
  55. + "日");
  56. } else
  57. System.out. println("且上一天為: " + 年+ "年" + 月+ "月"
  58. + (日- 1) + "日" + "," + "下一天為:" + 年+ "年"
  59. + 月+ "月" + (day + 1) + "日");
  60. } else
  61. System.out.println("您輸入的日期不合法");
  62. } else if (month == 4 | | 月== 6 || 月== 9 || 月== 11) {
  63. if (day >= 1 && day System.out. println("您輸入的日期為:" + 年+ "年" + 月+ "月"
  64. + day + "日");
  65. if (day == 30)
  66. System.out. println("且上一天為:" + 年+ "年" + 月+ "月"
  67. + (day - 1) + "日" + "," + "下一天為:" + 年+ "年"
  68. + (月+ 1) + "月1日");
  69. else if (day == 1)
  70. System.out.println("且上一天為:" + Year + "年" + (month - 1 )
  71. + "月31日" + "," + "下一天為:" + 年+ "年" + 月
  72. + (日+ 1) + "日");
  73. else
  74. System.out.println("且上一天為:" + 年+ "年" + 月+ "月"
  75. + (day - 1) + "日" + "," + "下日為:" + 年+ "年"
  76. + 月+ (day + 1) + "日");
  77. } else
  78. System.out.println("您輸入的日期不合法");
  79. }else if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
  80. if (day == 29)
  81. System.out.println("您輸入的日期為:" + year + "年" + month + "月"
  82. + day + "日" + "n" + "且上一天為:" + year + "年2月28日"
  83. + "," + "下一天為:" + year + "年3月1日");
  84. else {
  85. if (day == 28)
  86. System.out.println( "您輸入的日期為:" + year + "年" + month
  87. + "月" + day + "日" + "n" + "且上一天為:" + year
  88. + "年2月27日" + "," + "下一天為:" + year + "年2月29日");
  89. else
  90. System.out.println("您輸入的日期不合法");
  91. }
  92. }
  93. } else
  94. System.out.println("您輸入的日期不合法");
  95. }
  96. }
複製程式碼


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn