Package com.qunar.training.questionDate;
public class Permanent {
public static Boolean isleapyear (int year) {//Can be divisible by 4 but not divisible by 100, or divisible by 400
Boolean leapyear = false;
if (year% = = 0 && Year% 400 = = 0) | | (Year% + = 0 && Year% 4 = = 0)) {
Leapyear = true;
}
return leapyear;
}
public static int countdays (int year) {//Select a benchmark for January 1, 2015, Thursday
int countdays = 0;
int Beginyear =year > 2015? 2015:year;
int endyear = year > 2015? year:2015;
for (int i = Beginyear;i < endyear;i++) {
if (Isleapyear (i)) {
Countdays + = 366;
}else{
Countdays + = 365;
}
}
return countdays;
}
public static void Showcaledar (int year) {
int days = Countdays (year);
int weekDay = days% 7;
if (Year > 2015) {
WeekDay = (WeekDay + 4)% 7;
}else{
WeekDay = (11-weekday)% 7;
}
string[] Monthlabels = new string[]{"January", "February", "March", "April", "may", "June", "July", "August", "September", "October", "November", "December"};
string[] Weeklabels = new string[]{"Sun", "Mon", "Tur", "Wen", "Thr", "Fra", "Sat"};
Int[] MonthDay = {31,28,31,30,31,30,31,31,30,31,30,31};
for (int i = 0;i < 12;i++) {
System.out.println ("\ n" +monthlabels[i]);
for (String weeklabel:weeklabels) {//per week label
System.out.print (Weeklabel + "");
}
System.out.println (); Next line
for (int j = 0; J < WeekDay; J + +) {//Find First Date
System.out.print ("");
}
if (Isleapyear (year)) {
MONTHDAY[1] = 29;
}else{
MONTHDAY[1] = 28;
}
for (int k = 1;k <= monthday[i];k++) {
if ((k + weekDay-1)% 7 = = 0) {
System.out.println ();
}
if (K < 10) {//Here is the question of alignment
System.out.print (k + "");
}else{
System.out.print (k + "");
}
}
WeekDay = (WeekDay + monthday[i])% 7;
}
}
public static void Main (string[] args) {
Showcaledar (2014);
}
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Enter the year, then print out the perpetual calendar for that year, and identify the date of the day. Similar to the CAL-Y results under Linux.