日期:2014-05-20 浏览次数:20858 次
import java.util.*;
public class Test {
public static void main(String[] args) throws Throwable {
Scanner sc = new Scanner(System.in);
String buf;
int year;
GregorianCalendar c = new GregorianCalendar();
while (true) {
System.out.print("请输入年([yyyy]格式):");
buf = sc.nextLine();
try {
year = Integer.parseInt(buf);
if (year < 0) {throw new Exception("负数");}
System.out.println(c.isLeapYear(year) ? "闰年" : "不是闰年");
System.out.print("是否继续?(y/n):");
buf = sc.nextLine();
if ("y".equalsIgnoreCase(buf)) break;
} catch (Exception e) {
System.out.println("输入错误,请重输");
}
}
}
}