6.3w+
社区成员
//import java.util.GregorianCalendar;
import java.io.*;
//import java.util.Calendar;
import java.util.*;
public class Data {
/**
* @param args
*/
private int month;
private int year;
public Data(int year,int month)
{
this.year=year;
this.month=month;
}
private int GetDayNum()
{
int[] days={31,28,31,30,31,30,31,31,30,31,30,31};
GregorianCalendar cal=new GregorianCalendar(year,month,1);
if(cal.isLeapYear(year)&&month==2)
return days[month-1]+1;
else return days[month-1];
}
private int GetFirstDay()
{
Calendar cal=Calendar.getInstance();
cal.set(year, month-1,1);
return cal.get(Calendar.DAY_OF_WEEK);
}
public void ExportData()
{
System.out.println(year+"--"+month+":\n");
System.out.print("周日 周一 周二 周三 周四 周五 周六\n");
int spaces=GetFirstDay()-1;
for(int i=1;i<=spaces;i++)
{
System.out.print(" ");
}
/**
* print days
*/
int days=GetDayNum();
for(int d=1;d<=days;d++)
{
System.out.print(d+" ");
if((d+spaces)%7==0)
{
System.out.print("\n");
}
}
}
public static void main(String[] args) throws NumberFormatException, IOException {
// TODO Auto-generated method stub
Date now = new Date(System.currentTimeMillis());//
System.out.println("Begin: ( now, time is "+now+" )");
System.out.println("Please input the year you want to lookup:");
BufferedReader stin = new BufferedReader(new InputStreamReader(System.in));
int year = Integer.parseInt(stin.readLine());
System.out.println("Please input the month you want to lookup:");
//BufferedReader stin = new BufferedReader(new InputStreamReader(System.in));
int month = Integer.parseInt(stin.readLine());
Data dt=new Data(year,month);
dt.ExportData();
}
}