TheProgramThe integrated environment used is myeclipse.
Functions of this perpetual calendar:
1. Determine the correctness of the year and month entered by the user.
2. Determine whether the year entered by the user is a leap year
3. Calculate the number of days of the year entered by the user
4. Calculate the number of days of the month input by the user.
5. print the number of days of the month according to the date and time attribute of the window system.
Note: Code Added comments inPackage hamber_bao; </P> <p> Import Java. util. callback; </P> <p> public class wnl {<br/> Public static void wnlmethod () {<br/> specify input = new callback (system. in); </P> <p> int I; <br/> int year; // year for receiving user input <br/> int month; // receives the month input by the user <br/> Boolean XN; // declares a Boolean variable, to mark the correctness of the year and month entered by the user </P> <p> // use the do-while loop to determine the correctness of the year and month entered by the user, XN mark <br/> do {<br/> system. out. print ("Enter the year:"); <br/> year = input. nextint (); <br/> system. O Ut. println (); <br/> system. out. print ("Enter the month:"); <br/> month = input. nextint (); <br/> system. out. println (); <br/> xn = (year <1) | (month> 12) | (month <1); <br/> If (Xn) <br/> system. out. println ("sorry, your input is incorrect! Enter again! "); <Br/>}while (Xn); </P> <p> int everyyearday = 0; // receives the number of days per year. <br/> int totalyearsdays = 0; // total number of days of the receiving year <br/> int inputyearday = 0; // number of days of the year input by the receiving user <br/> Boolean YN = false; // indicates whether the year is a leap year </P> <p> for (I = 1900; I <= year; I ++) {<br/> // determine whether it is a leap year <br/> If (I % 4 = 0) & (I % 100! = 0) | (I % 400 = 0) {<br/> YN = true; <br/> everyyearday = 366; <br/>} else {<br/> YN = false; <br/> everyyearday = 365; <br/>}< br/> // calculate the total number of days from January 1, 1900 to the end of (year-1). <br/> if (I <year) {<br/> totalyearsdays = totalyearsdays + everyyearday; <br/>}< br/> // formatted output <br/> else {</P> <p> inputyearday = everyyearday; <br/> If (yn) {<br/> system. out. println (Year + "year/T is a leap year/T total" + inputyearday + "day"); <br/>} else {<br/> system. out. println (Year + "year/T is normal year/T total" + inputyearday + "day"); <br/>}< br/> system. out. println (); <br/>}</P> <p> int everymonthday = 0; // receive the number of days per month <br/> int totalmonthsdays = 0; // total number of days of the month to be received </P> <p> // determine the number of days of each month in a cyclic month <br/> for (I = 1; I <= month; I ++) {<br/> // determine the month <br/> switch (I) {<br/> case 4: <br/> case 6: <br/> case 9: <br/> case 11: <br/> everymonthday = 30; <br/> break; <br/> case 2: <br/> If (yn) {<br/> everymonthday = 29; <br/>}else {<br/> everymonthday = 28; <br/>}< br/> break; <br/> default: <br/> everymonthday = 31; <br/> break; <br/>}< br/> // calculates the number of days for the period from January 1, January to month. <br/> if (I <month) {<br/> totalmonthsdays = totalmonthsdays + everymonthday; <br/>}else {</P> <p> system. out. println (month + "month/T total" + everymonthday + "day"); <br/> system. out. println (); <br/>}</P> <p> int Total = totalyearsdays + totalmonthsdays; // The number of days of the month from January 1, January 1, 1900 to the year (month <br/> //-1) </P> <p> int temp = (total + 1) % 7; // calculate the total number of days plus the first day of month, and then take the remainder </P> <p> // format the output <br/> system. out. println ("Sunday/T Monday/t Tuesday/T Wednesday/T Friday/T Saturday "); </P> <p> // print space <br/> for (I = 0; I <temp; I ++) {<br/> system. out. print ("/t"); <br/>}< br/> // output each day of month <br/> for (I = 1; I <= everymonthday; I ++) {<br/> // judgment: if the total number of days is plus the number I in month, if the modulus 7 = 6, <br/> If (total + I) % 7 = 6) {<br/> system. out. println (I); <br/>}else {<br/> system. out. print (I + "/t"); <br/>}< br/> system. out. println ("/n"); <br/>}< br/>
<textarea cols="84" rows="15" name="code" class="java">Package hamber_bao; </P> <p> Import Java. util. struct; </P> <p> public class startwnl {<br/> Public static void main (string [] ARGs) {<br/> specify input = new struct (system. in); <br/> string answer; </P> <p> system. out <br/>. println ("-------------------------------- welcome to use Perpetual calendar ----------------------------"); <br/> system. out <br/>. println ("by hamber_bao/n"); </P> <p> do {<br/> wnl. wnlmethod (); <br/> system. out. PRI Ntln ("Continue query? (Y/n) "); <br/> answer = input. next (); </P> <p >}while (answer. equalsignorecase ("Y"); <br/> system. out. println ("program ended! Thank you for your use! "); <Br/>}</P> <p>}</textarea>
2010-05-22
By hamber_bao