首页  >  文章  >  后端开发  >  一位态度非常认真的学生写的代码

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

WBOY
WBOY原创
2016-07-25 09:08:15784浏览
  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 if (month == 1 || month == 3 || month == 5 || month == 7
  24. || month == 8 || month == 10 || month == 12) {
  25. if (day >= 1 && day System.out.println("您输入的日期为:" + year + "年" + month + "月"
  26. + day + "日");
  27. if (day == 31) {
  28. if (month == 12)
  29. System.out.println("且上一天为:" + year + "年12月"
  30. + (day - 1) + "日" + "," + "下一天为:"
  31. + (year + 1) + "年1月1日");
  32. else
  33. System.out.println("且上一天为:" + year + "年" + month
  34. + "月" + (day - 1) + "日" + "," + "下一天为:"
  35. + year + "年" + (month + 1) + "月1日");
  36. } else if (day == 1) {
  37. if (month == 1)
  38. System.out.println("且上一天为:" + (year - 1)
  39. + "年12月31日" + "," + "下一天为:" + year + "年"
  40. + month + "月" + (day + 1) + "日");
  41. else if (month == 3) {
  42. if ((year % 4 == 0 && year % 100 != 0)
  43. || (year % 400 == 0))
  44. System.out.println("且上一天为:" + year + "年2月29日"
  45. + "," + "下一天为:" + year + "年" + month
  46. + "月" + (day + 1) + "日");
  47. else
  48. System.out.println("且上一天为:" + year + "年2月28日"
  49. + "," + "下一天为:" + year + "年" + month
  50. + "月" + (day + 1) + "日");
  51. } else
  52. System.out.println("且上一天为:" + year + "年"
  53. + (month - 1) + "月30日" + "," + "下一天为:"
  54. + year + "年" + month + "月" + (day + 1)
  55. + "日");
  56. } else
  57. System.out.println("且上一天为:" + year + "年" + month + "月"
  58. + (day - 1) + "日" + "," + "下一天为:" + year + "年"
  59. + month + "月" + (day + 1) + "日");
  60. } else
  61. System.out.println("您输入的日期不合法");
  62. } else if (month == 4 || month == 6 || month == 9 || month == 11) {
  63. if (day >= 1 && day System.out.println("您输入的日期为:" + year + "年" + month + "月"
  64. + day + "日");
  65. if (day == 30)
  66. System.out.println("且上一天为:" + year + "年" + month + "月"
  67. + (day - 1) + "日" + "," + "下一天为:" + year + "年"
  68. + (month + 1) + "月1日");
  69. else if (day == 1)
  70. System.out.println("且上一天为:" + year + "年" + (month - 1)
  71. + "月31日" + "," + "下一天为:" + year + "年" + month
  72. + (day + 1) + "日");
  73. else
  74. System.out.println("且上一天为:" + year + "年" + month + "月"
  75. + (day - 1) + "日" + "," + "下一天为:" + year + "年"
  76. + month + (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