JAVA,
分享于 点击 4928 次 点评:96
JAVA,
package hello;
import java.util.InputMismatchException;
import java.util.Scanner;
public class Date {
static int date_input() {
Scanner in = new Scanner(System.in);
int date = 0;
try {
date = in.nextInt();
} catch (InputMismatchException e) {
System.out.println("输入有误\n请重新输入!");
date_input();
}
return date;
}
public static void main(String[] args) {
while (true) {
System.out.println("请输入年:");
int year = date_input();
System.out.println("请输入月:");
int month = date_input();
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
System.out.println("31天");
}
else if (month == 4 || month == 6 || month == 9 || month == 11) {
System.out.println("30天");
}
else if (month == 2) {
if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) {
System.out.println("29天");
}
else {
System.out.println("28天");
}
}
}
}
}
相关文章
- 暂无相关文章
用户点评