當前位置:編程學習大全網 - 編程軟體 - java新手問個用多重if語句 實現閏年和年份月份的程序,做的頭暈了...

java新手問個用多重if語句 實現閏年和年份月份的程序,做的頭暈了...

不是說妳沒有分,人家不幫妳。

看到妳的問題了,我們還得現做,再測,要時間的。

要是是感興趣的問題,不給分壹樣做的。

參考壹下吧,有什麽問題再問。或是我的程序有什麽不對的地方,指壹下。

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 + "天");

}

  • 上一篇:軟件hook是什麽
  • 下一篇:請幫我推薦壹款吃雞遊戲鼠標。
  • copyright 2024編程學習大全網