Import Java.util.scanner;public class Calender {public static Boolean isrun (int year)//determines whether a leap year {if (year%4==0 && year%100!=0) | | (year%400==0)) {return true;} Else{return false;}} public static int Calday (int year,int mth)//Determine the month of the year how many days {int Days=31;switch (MTH) {case 4:case 6:case 9:case 11:days=30; Break;case 2:if (Isrun (year)) {days=29;} else{days=28;} break;} return days;} public static int Calfirstday (int year,int mth)//Judging is the first day of the month and the second of the week {int firstday=0;//1900-01-01 Monday int i=1901;int tmpday= 0;for (i=1900;i<year;i++) {if (Isrun (i)) tmpday=tmpday+366;elsetmpday=tmpday+365;} int H=1;for (h=1;h<mth;h++) {tmpday=tmpday+calday (year,h);} Firstday=tmpday%7;return FirstDay;} public static void Main (string[] args) {//TODO auto-generated method stub int year,mth; Scanner ysc=new Scanner (system.in); System.out.println ("Please enter the Year:"); Year=ysc.nextint (); if (Isrun (year)) {System.out.println (year+ "is a leap year"); } System.out.println ("Please enter month:"); Mth=ysc.nextint (); Ysc.close (); System.out.println ("********** calendar ********" +year+ "year" +mth+ "month" + "*****************"); System.out.println ("Sunday \ t Monday \ t Tuesday \ t Wednesday \ Thursday \ t Friday \ t Saturday"); int counttimes=0; for (int i=0;i<=calfirstday (year,mth); i++) {System.out.print ("\ t"); counttimes++; } for (int lp=1;lp<=calday (year,mth); lp++) {System.out.print (lp+ "\ t"); counttimes++; if (counttimes%7==0) {System.out.println (); } }}}
A simple example of learning Java calendar