看到妳的問題了,我們還得現做,再測,要時間的。
要是是感興趣的問題,不給分壹樣做的。
參考壹下吧,有什麽問題再問。或是我的程序有什麽不對的地方,指壹下。
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
System.out.println("請輸入年份:");
String strYear = in.next();
System.out.println("請輸入月份:");
String strMonth = in.next();
while (!strMonth.matches("0?[1-9]|1[012]")){
System.out.println("輸入的月份錯誤,請輸入1-12之間的值。");
strMonth = in.next();
}
GregorianCalendar gc = new GregorianCalendar(Integer.parseInt(strYear),
Integer.parseInt(strMonth) - 1, Calendar.DATE);
GregorianCalendar gc1 = new GregorianCalendar(
Integer.parseInt(strYear), (Integer.parseInt(strMonth)),
Calendar.DATE);
Long dayNum = (gc1.getTimeInMillis() - gc.getTimeInMillis())
/ (1000 * 60 * 60 * 24);// 用下個月的第壹天減去這個月的第壹天(毫秒)
if (strMonth.matches("0?2") && gc.isLeapYear(Integer.parseInt(strYear))) // 這裏有直接判斷閏年的方法
System.out.println("這是閏年");
System.out.println(strYear + "年" + strMonth + "月有" + dayNum + "天");
}