显示一年的日历
import javax.swing.*;
public class xin{
public static void main(String[] args) {
String year1=JOptionPane.showInputDialog("Enter a year");
int year=Integer.parseInt(year1);
String day1=JOptionPane.showInputDialog("Today is");
int day=Integer.parseInt(day1);
int []month_day={31,28,31,30,31,30,31,31,30,31,30,31};
if((year%4==0&&year%100!=0)||(year%400)==0)
month_day[1]=29;
String []weekend={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
String []month={"January","February","March","April","May","June","July","August","September","October","November","December"};
for(int j=0;j<12;j++)
{
System.out.println(" "+month[j]+" "+year);
System.out.println(" ---------------------------------------------------------------");
for(int i=0;i<7;i++)
System.out.printf("%10s",weekend[i]);
System.out.println();
day=day%7;
for(int y=0;y<day;y++)
System.out.print(" ");
for(int t=0;t<month_day[j];t++)
{
System.out.printf("%10d",t+1);
day++;
if(day%7==0)
System.out.println();
}
System.out.println();
}
}
}