个人觉得楼主与题目要求不是很规范 望批评指教 public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入年月日(使用空格隔开)"); while (sc.hasNext()){ String time = sc.nextLine(); String[] s = time.split("\\s+"); int year = Integer.parseInt(s[0]); int month = Integer.parseInt(s[1]); int day = Integer.parseInt(s[2]); if(month <=12 && day<=31){ if((month==2&&day<=28)||(is_Leap(year)&&month==2&&day<=29)||(month!=2)){ int[] month_day = {31,28,31,30,31,30,31,31,30,31,30,31}; int sum = 0; for (int i = 0; i < month - 1; i++) { sum += month_day[i]; } sum += day; if (year>=0 && month > 2 && is_Leap(year) ){ sum += 1; } System.out.println(sum); }else { System.out.println("非闰年的2月只有28天哟"); } }else { System.out.println("请输入正确的年月日"); } } } public static boolean is_Leap (int n){ if(n % 4 == 0 && n % 100 != 0 || n % 400 == 0){ return true; }else { return false; } }
1

相关推荐

头顶尖尖的程序员:我是26届的不太懂,25届不应该是找的正式工作吗?为什么还在找实习?大四还实习的话是为了能转正的的岗位吗
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务