import java.io.*;
//局部變量的使用
import java.util.Scanner;
//局部變量的使用
import java.util.Scanner;
public class HelloJava {
public static void main(String args[]) {
//通過scanner類來獲取用戶輸入
Scanner scanner = new Scanner(System.in);
Scanner scanner = new Scanner(System.in);
//調用的變量輸入值是整型,不支持大寫漢字年份
System.out.println("請輸入年份:");
int year = scanner.nextInt();
System.out.println("請輸入月份:");
int month = scanner.nextInt();
int dayNum = theDayNum(month);
if (isLeapYear(year)) {
if (month == 2) {
dayNum++;
System.out.println("請輸入年份:");
int year = scanner.nextInt();
System.out.println("請輸入月份:");
int month = scanner.nextInt();
int dayNum = theDayNum(month);
if (isLeapYear(year)) {
if (month == 2) {
dayNum++;
}
System.out.print(year + "是閏年");
} else {
System.out.print(year + "是閏年");
} else {
System.out.print(year + "不是閏年");
}
System.out.println(year + "年" + month + "月份共有" + dayNum + "天");
System.out.println(year + "年" + month + "月份共有" + dayNum + "天");
}
//判斷閏年
public static boolean isLeapYear(int year) {
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
return true;
} else {
return false;
}
}
//判斷天數
public static boolean isLeapYear(int year) {
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
return true;
} else {
return false;
}
}
//判斷天數
public static int theDayNum(int month) {
switch (month) {
case 1:
return 31;
case 2:
return 28;
case 3:
return 31;
case 4:
return 30;
case 5:
return 31;
case 6:
return 30;
case 7:
return 31;
case 8:
return 31;
case 9:
return 30;
case 10:
return 31;
case 11:
return 30;
case 12:
return 31;
default:
System.out.println("對不起,您輸入的月份有誤!");
return 0;
}
}
}
switch (month) {
case 1:
return 31;
case 2:
return 28;
case 3:
return 31;
case 4:
return 30;
case 5:
return 31;
case 6:
return 30;
case 7:
return 31;
case 8:
return 31;
case 9:
return 30;
case 10:
return 31;
case 11:
return 30;
case 12:
return 31;
default:
System.out.println("對不起,您輸入的月份有誤!");
return 0;
}
}
}