判断某一年是否为闰年

 1 package 判断某一年是否为闰年;
 2 
 3 import java.util.Scanner;
 4 
 5 public class If_LeapYear {
 6     public static void main(String[] args) {
 7         System.out.println("请输入年份");
 8         Scanner input=new Scanner(System.in);
 9         boolean loop=true;
10 loop1:  while(loop){
11              try {
12                  int year=input.nextInt();
13                  if(year%4==0&&year%100!=0||year%400==0){
14                      System.out.println(year+"是闰年!是否还要继续:1表示是,2表示否");
15                      int num=input.nextInt();
16                      if(num==1){
17                         continue loop1; 
18                      }
19                  }else{
20                      System.err.println(year+"不是闰年!是否还要继续:1表示是,2表示否");
21                      int num=input.nextInt();
22                      if(num==1){
23                         continue loop1; 
24                      }
25                  }
26                 
27             } catch (Exception e) {
28                 System.out.println("您不是输入的有效年份,请重新输入!");
29                 continue;
30             }
31             loop=false;
32         }
33     }
34 }

 

posted @ 2017-07-03 12:12  一根绿毛  阅读(674)  评论(0编辑  收藏  举报