Traditional Culture Encyclopedia - The 24 Solar Terms - Java calculates lunar calendar date
Java calculates lunar calendar date
* @param args
*/
Public static void main(String[] args) {
System. out . println(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");
Scanner input = new scanner (system. in);
System.out.print ("\ nPlease select year:");
int year = input . nextint();
System.out.print ("\ nPlease select the month:");
int month = input . nextint();
system . out . println(); int days = 0; //Store the date of the current month.
Boolean isRn
/* Judge whether it is a leap year */
If (year% 4 = = 0 & amp& amp (year%100 = = 0) || year% 400 = = 0) {//Judge whether it is a leap year.
IsRn = true// leap year
} Otherwise {
IsRn = false// average year
}/* Calculate the number of days before entering the year */
int total days = 0;
for(int I = 1900; My< year; i++) {
/* Judge leap year or average year and accumulate days */
if(I % 4 = = 0 & amp; & amp! (i% 100 == 0) || i% 400 == 0) {// Judge whether it is a leap year.
Total days = total days+366; //leap year 366 days
} Otherwise {
Total days = total days+365; //365 days in normal year
}
}/* Calculate the number of days before the input month */
int before days = 0;
for(int I = 1; I < = month; i++) {
Switch (i) (
Case 1:
Case 3:
Case 5:
Case 7:
Case 8:
Case 10:
Case 12:
Days = 31;
Break;
Case 2:
if (isRn) {
Days = 29;
} Otherwise {
Days = 28;
}
Break;
Default value:
Days = 30 days;
Break;
}
If (I< month) {
Days before = Days before+Days;
}
}
Total days = total days+previous days; //1900 65438+1October 1/* Calculate the day of the week */
Int firstDayOfMonth// stores the day of the week on the first day of the month: Sunday is 0, and Monday to Saturday is 1~6.
Int temp = 1+Total days% 7; //Calculated from 65438+65438+ 10 in 0900.
If (temp == 7) {// Find the first day of the month.
first day of month = 0; //Sunday
} Otherwise {
firstDayOfMonth = temp
}/* Output calendar */
System.out.println ("Sunday \t Monday \t Tuesday \t Wednesday \t Thursday \t Friday \t Saturday ");
for(int null no = 0; nullNo & ltfirstDayOfMonthnullNo++) {
system . out . print(" \ t "); //output spaces
}
for(int I = 1; I<= days; i++) {
system . out . print(I+" \ t ");
If ((total days +I- 1)% 7 = = 5){// If the day is Saturday, the output will wrap.
system . out . println();
}
}
}
}
- Previous article:Does anyone know what love is? Give me a general plot, thank you.
- Next article:What is the best regimen in Tomb-Sweeping Day?
- Related articles
- Words related to solar terms
- How did you spend the beginning of autumn Festival in Liu Shao Township, Xundian County, Kunming City, Yunnan Province?
- Can you make money by opening a clothing store now?
- Here are two EXCEL tables, how to use the known solar terms and years. Find the corresponding lunar date and time respectively? (***4 functions)
- Summer is the last solar term in summer ().
- Solar terms flower arrangement design
- Recite the formula of the first grade history knowledge points.
- What farming activities are there in the 24 solar terms?
- What does low carbon mean?
- Is Qingming Tomb-Sweeping Day? Is Qingming Tomb-Sweeping Day?