首页 > 其他 > 详细

编写程序,判断给定的某个年份是否是闰年。

时间:2015-01-20 00:52:05      阅读:232      评论:0      收藏:0      [点我收藏+]

编写程序,判断给定的某个年份是否是闰年。       
闰年的判断规则如下: 
(1)若某个年份能被4整除但不能被100整除,则是闰年。       
(2)若某个年份能被400整除,则也是闰年。
解答:

import java.util.*;
public class Bissextile{
    public static void main(String[]arge){
        System.out.println("please input the nian:");
    int year;
    Scanner scanner = new Scanner(System.in);
    year = scanner.nextInt();
    if(year<0||year>3000){
        System.out.println("the Year is wrong,exit!");
        System.exit(0);
    }
    if((year%4==0)&&(year%100!=0)||(year%400==0))
        System.out.println(year+"is bissextile");
    else
        System.out.println(year+"is not bissextile");
    }    
}

2015-01-19 23:38:36

编写程序,判断给定的某个年份是否是闰年。

原文:http://www.cnblogs.com/Rainbow-G/p/4235046.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!