This article illustrates the simple perpetual calendar of Java implementations. Share to everyone for your reference, specific as follows:
Import Java.util.Scanner;
public class Printcalendar {public static void main (string[] args) {int years = 0;
int month = 0;
int days = 0;
Boolean isrun = false;
From the console input year, the month Scanner input = new Scanner (system.in);
System.out.print ("Please enter the Year:");
years = Input.nextint ();
System.out.print ("Please enter the month:");
month = Input.nextint ();
System.out.println ("\n*********" +years+ "year" +month+ "calendars table ************"); Determine if it is a leap year if ((years% 4 = 0 && years% 100!= 0) | | (years% 400 = 0))
{Isrun = true; int totaldays = 0; Count of days//calculate distance from January 1, 1900 for (int i = 1900 I < years; i++) {if ((i% 4 = 0 && i% 100!= 0) | | (i% 400 = 0))
{totaldays = totaldays + 366;
}else{totaldays = totaldays + 365;
an int beforedays = 0; According to the number of days for (int j = 1; J <= Month + +) {switch (j) {case 1:case 3:case 5:case 7:case 8:case 10:case 1
2:days = 31;
Break
Case 4:case 6:case 9:case 11:days = 30;
Break
Case 2:if (isrun) {days = 29; }else{Days = 28;
} default:System.out.println ("Input month incorrect!!");
} if (J < month) {beforedays = beforedays + days; } totaldays = Totaldays + beforedays;
The current total number of int firstdayofmonth = 0;
int temp = 1 + totaldays% 7;
if (temp = 7) {firstdayofmonth = 0;//Monday}else{Firstdayofmonth = temp;
/* Output calendar/System.out.println ("Sunday \ t Monday \ Tuesday \ Wednesday \ Thursday \ t Friday \ Saturday");
for (int k = 0; k < firstdayofmonth; k++) {System.out.print ("T");
for (int m = 1; m <= days; m++) {System.out.print (M + "t");
if ((Totaldays + m)% 7 = 6) {System.out.print ("\ n");
}
}
}
}
About the calendar of the production of interested friends can also refer to the site online tools:
Online Perpetual calendar
Web Calendar
I hope this article will help you with Java programming.