我以前做过的一个日历,你可以改一下就OK了!
其实是很容易 了
import java.util.*;
import java.io.*;
class CalendarTest {
static int strToInt;
static String s="";
public static void getInfo()
{
try
{
BufferedReader cin=new BufferedReader (new InputStreamReader(System.in));
s=cin.readLine();
strToInt=Integer.parseInt(s);
}catch(Exception e){};
}
public static void main(String[] args)
{
int year;
int month;
Calendar calendarObj=Calendar.getInstance();
System.out.print("请输入你想查询日历的年份:");
getInfo();
year=strToInt;
System.out.println();
System.out.print("请输入你想查询日历的月份:");
getInfo();
month=strToInt;
calendarObj.set(year,month-1,1);
int weeks=calendarObj.get(Calendar.DAY_OF_WEEK)-1;
System.out.println();
System.out.println(year+"年"+month+"月的日历如下:");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println('日'+" "+'一'+" "+'二'+" "+'三'+" "+'四'+" "+'五'+" "+'六');
String[] count=new String[weeks+31];
for(int i=0;i<weeks;i++)
{
count[i]="**";
}
for(int i=weeks,n=1;i<weeks+31;i++)
{
if(n<=9)
count[i]=" "+String.valueOf(n);
else
count[i]=String.valueOf(n);
n++;
}
for(int i=0;i<weeks+31;i++)
{
if(i%7==0)
{
System.out.println();
System.out.print(count[i]+" ");
}
else
System.out.print(count[i]+" ");
}
System.out.println();
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~");
}
}