?? mycalendar.java
字號:
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.*;
public class Mycalendar extends GregorianCalendar
{
public static void main(String args[])
{
BufferedReader reader = new BufferedReader
(new InputStreamReader(System.in));
String line = "";
int temp = 0;
int weakNum = 0;
int monthNum = 0;
int[]days = {31,28,31,30,31,30,31,31,30,31,30,31};
Calendar c = GregorianCalendar.getInstance();
Date nowMonth = new Date();
Date nowDay = new Date();
//獲取當前月份
SimpleDateFormat matter1 =
new SimpleDateFormat("MM");
int mm=Integer.parseInt(matter1.format(nowMonth));
//獲取當前日
SimpleDateFormat matter2 =
new SimpleDateFormat("dd");
int d=Integer.parseInt(matter2.format(nowDay));
// System.out.print(mm);
//控制輸入周數
System.out.print("please input weakNum:");
try
{
line = reader.readLine();
temp = (new Integer(line)).intValue();
}
catch(Exception e){}
weakNum = temp;
monthNum = weakNum/4;
//控制輸入年份
System.out.print("please input year:");
try
{
line = reader.readLine();
temp = (new Integer(line)).intValue();
}
catch(Exception e){}
c.set(Calendar.YEAR,temp);
//控制輸入月份
System.out.print("please input month:");
try
{
line = reader.readLine();
temp = (new Integer(line)).intValue();
}
catch(Exception e){}
if(temp<1&&temp>12)
{
System.out.println("month must be between 1 and 12.");
System.out.println(0);
}
temp--;
c.set(Calendar.MONTH,temp);
int month = c.get(Calendar.MONTH);
int year = c.get(Calendar.YEAR);
//顯示輸出各月份日歷
System.out.println("\n ***************校 歷**************");
for(int k=1;k<=monthNum;k++)
{
if((year%4==0&&year%100!=0||year%400==0)&&month==2)
days[2]++;
System.out.println(" <-----------"+year+"年"+(month+1)+"月份---------->");
System.out.println(" SUN MON TUE WED THU FRI SAT");
c.set(DATE,1);
c.set(Calendar.MONTH,month);
c.set(Calendar.YEAR,year);
int first=c.get(Calendar.DAY_OF_WEEK);
for(int i=1;i<first;i++)
System.out.print(" ");
for(int i=1;i<=days[month];i++)
{
if(i<10)
System.out.print(" ");
if(month+1==mm&&i==d)
System.out.print(" "+"*"+i);
else
System.out.print(" "+i);
// System.out.print(" ");
if(first++%7==0)
System.out.println("");
}
month++;
if(month==13)
{
month = 0;
year++;
}
System.out.println("\n\n");
}
System.out.println("\n");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -