UT source code 149, ut source code 149
(2) NextDate function problems
NextDate indicates a complex relationship, that is, the complexity of the logical relationship between input variables.
The NextDate function contains three variables: month, day, and year. The output of the function is the date of the day after the input date. The input values month, day, and year must be integer values and meet the following conditions:
Condition 1 ≤ month ≤ 12 otherwise output, the month exceeds the range
Condition 2 1 ≤ day ≤ 31 otherwise output, date out of range
Condition 3 1912 ≤ year ≤ 2050 otherwise output: The year exceeds the range
String nextdate (int m, int d, int y)
Note that the returned value is a string.
Program requirements:
1) display "enter date" first"
2) If condition 1 is not met, return: "the month is out of range"; if condition 2 is not met, return: "the date is out of range"; if Condition 3 is not met, return: "The year is out of the range". If multiple non-conformities occur, the system returns the information with the first non-conformities.
3) if all the conditions are met, the date of the next day is output. The format is "**** year month Day". (If you enter December 31, 2050, January 1, 2051 is displayed normally.
1 package com. test; 2 import java. util. required; 3 public class TestPractice {4/* leap year judgment 5 * return value true: This year is leap year 6 * return value is false: this year is the year 7 */8 public static boolean isLeapYear (int y) 9 {10 if (y % 4 = 0 & y % 100! = 0) | y % 400 = 0) 11 return true; 12 else13 return false; 14} 15 16 // determine the next day. The return value is the date of the next day, format: xxxx, month, day, 17 public static String NextDate (int y, int m, int d) 18 {19 // determine if the year exceeds the range of 20 if (1912 <= y & y <= 2050) 21 {22 // determine whether the month has exceeded the range of 23 if (1 <= m & m <= 12) 24 {25 // large month judgment, only 31 days 26 if (m = 1 | m = 3 | m = 5 | m = 7 | m = 8 | m = 10 | m = 12) 27 {28 if (1 <= d & d <30) 29 return y + "year" + m + "month" + (d + 1) + "day "; 30 else if (d = 31) 31 {32 if (m = 12) 33 return (y + 1) + "January 1 "; 34 else 35 return y + "year" + (m + 1) + "Month 1"; 36} 37 else 38 return "date out of range "; 39} 40 // small month judgment, only 30 days a month 41 else if (m = 4 | m = 6 | m = 9 | m = 11) 42 {43 if (1 <= d & d <29) 44 return y + "year" + m + "month" + (d + 1) + "day "; 45 if (d = 30) 46 return y + "year" + (m + 1) + "Month 1"; 47 else48 return "date out of range "; 49} 50/* the number of days in July is different from that in the year of the Year of the year )) 56 {57 if (1 <= d & d <28) 58 return y + "year" + m + "month" + (d + 1) + "day "; 59 if (d = 29) 60 return y + "year" + (m + 1) + "Month 1"; 61 else62 return "date out of range "; 63} 64 else65 {66 if (1 <= d & d <27) 67 return y + "year" + m + "month" + (d + 1) + "day"; 68 if (d = 28) 69 return y + "year" + (m + 1) + "Month 1 day "; 70 else71 return "date out of range"; 72} 73} 74 75} 76 else77 return "month out of range"; 78} 79 else80 {81 return "year out of range "; 82} 83 84} 85 86 public static void main (String [] args) {87 bytes scan = new bytes (System. in); 88 while (true) 89 {90 System. out. print ("enter date:"); 91 int y = scan. nextInt (); 92 if (y =-1) break; 93 int m = scan. nextInt (); 94 int d = scan. nextInt (); 95 System. out. println (NextDate (y, m, d); 96} 97} 98 99}