判断闰年
来源:互联网 发布:js 定时执行 编辑:程序博客网 时间:2024/05/22 16:53
package com.liaojianya.chapter1;import java.util.Scanner;/** * This program demonstrates the way of judging leap year. * @author LIAO JIANYA * 2016年7月19日 */public class LeapYear{public static void main(String[] args){@SuppressWarnings("resource")Scanner scan = new Scanner(System.in);System.out.println("Please enter the year: ");int year = (int)scan.nextInt();if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0){System.out.println(year + " is leap year!");}else{System.out.println(year + " is not leap year!");}}}
运行结果1:
Please enter the year: 20042004 is leap year!
运行结果2:
Please enter the year: 20172017 is not leap year!
运行结果3:
Please enter the year: 40004000 is leap year!
分析:
判断闰年一般的规律为: 四年一闰,百年不闰,四百年再闰.
其简单计算方法:1.能被4整除而不能被100整除.(如2016年就是闰年,1800年不是.)
2.能被400整除.(如2000年和4000年都是闰年)
0 1
- 判断闰年 输出闰年
- 判断闰年
- 判断闰年
- 闰年判断
- 判断闰年
- 判断闰年
- 判断闰年
- 判断闰年
- 判断闰年
- 判断闰年
- 判断闰年
- 判断闰年
- 判断闰年
- 判断闰年
- 判断闰年
- 判断闰年
- 闰年判断
- 判断闰年
- python string转换为tuple (by list)
- spring整合hibernate加sqlite数据库
- MySQL-python For OSX Install Failed
- Git 分支讲解-好
- Java中如何遍历Map对象的4种方法
- 判断闰年
- 168. Excel Sheet Column Title
- python——列表与元组
- tjut 1712
- Hibernate的二级缓存概述
- 【HDU】1250 - Hat's Fibonacci(java - BigDecimal)
- SpringMVC结合ajaxfileupload.js实现文件无刷新上传
- 常用的Excel编辑步骤和公式使用
- 使用switch case语句来显示月份的对应天数