Import Java.util.Scanner;
Class Calendarmain
{
Main function entry
public static void Main (string[] args)
{
SYSTEM.OUT.PRINTLN ("* * * * * Please enter the date (format: 2011-01) * * * * *);
Scanner sc = new Scanner (system.in);
String ym = Sc.next ();
Intercept string
string[] Yearmonth = Ym.split ("-");
Convert a string into an integer type
int year = integer.parseint (yearmonth [0]);
int month = Integer.parseint (yearmonth [1]);
Year.fun (year);
Month.fun (month,year);
}
}
Get the number of leap years
Class year
{
Number of leap years
static int leapyear = 0;
public static void Fun (int year) {
if (Year > 1990 && year <10000) {
while (year >= 1990) {
if (year% 4 = = 0 && Year% 100! = 0 | | (Year% 400 ==0)) {
Leapyear + +;
}
Year--;
}
}else{
System.out.println ("Please enter the year of the query greater than or equal to 1990 years!");
}
}
}
Get one months how many days and total days
Class Month
{
public static void Fun (int. month,int year) {
int monthday = 0;
Year y = New Year ();
int days = Y.leapyear + (year-1990) *365;
if (Month > 0 && month <=12) {
for (int i = 1;i <= month;i++) {
if (I < 8 && i! = 2) {
Days + = i% 2 = = 1? 31:30;
MonthDay = i% 2 = = 1? 31:30;
}
if (i > 7) {
Days + = i% 2 = = 1? 30:31;
MonthDay = i% 2 = = 1? 30:31;
}
if (i = = 2) {
if (year% 4 = = 0 && Year% 100! = 0 | | (Year% 400 ==0)) {
Days + = 28;
MonthDay = 29;
}else{
Days + = 28;
MonthDay = 28;
}
}
}
Show.mothed (Days,monthday);
}else{
System.out.println ("Please enter the correct month!") ");
}
}
}
Show Calendar
Class Show
{
public static void mothed (int days, int monthday) {
Plus one means starting from Monday
Int week = (days-monthday)% 7 + 1;
System.out.println ("\ n Sunday" + "\ t Monday" + "\ t Tuesday" + "\ t Wednesday" + "\ t Thursday" + "\ t Friday" + "\ t Saturday");
for (int i = 1;i <= monthday + week; i++)
{
if (I <= week) {
System.out.print ("" + "*" + "\ T");
}else{
if ((I-week) < 10) {
System.out.print ("" + (I-week) + "\ T");
}else{
System.out.print ((i-week) + "\ T");
}
}
if (i%7 = = 0) {
System.out.print ("\ n");
}
}
}
}
The Java calendar displays the year, month