判断某一年是否为闰年

 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 }
时间: 2024-07-30 17:27:13

判断某一年是否为闰年的相关文章

c语言判断某一年是否为闰年的各种实现程序代码

本文导语: c语言判断某一年是否为闰年的各种实现程序代码1.公历闰年计算原则(按一回归年365天5小时48分45.5秒)1)普通年能整除4且不能整除100的为闰年.(如2004年就是闰年,1900年不是闰年)2)世纪年能整除400的是闰年.(如2000年是闰年... c语言判断某一年是否为闰年的各种实现程序代码 1.公历闰年计算原则(按一回归年365天5小时48分45.5秒) 1)普通年能整除4且不能整除100的为闰年.(如2004年就是闰年,1900年不是闰年) 2)世纪年能整除400的是闰年

C语言判断1000—2000年之间的闰年

闰年判断方法: 1.能被400整除的年份: 2.能被4整除但同时不能被100整除的年份. 满足上述两个条件之一的即为闰年. 以下展现了三种形式 第一种: #include<stdio.h> int main() { int year,leap,count=0;     for(year=1000;year<=2000;year++)     {if(year%4==0)      {if(year%100==0)      {      if(year%400==0)          

Java实例——判断某一年是否为闰年

技术关键: 满足两种条件的整数可以成为闰年: 1.非整百年份能被4整除: 2.整百年份能被400整除. Java语法: year % 4 == 0 && year % 100 != 0 || year % 400 == 0 实现过程: 1 package test; 2 import java.util.Scanner; 3 public class LeapYear { 4 public static void main(String[] args) { 5 // TODO Auto-g

判断给定的年份是否为闰年

#!/usr/bin/env python #coding:utf-8 def f(x):     if x%400 == 0 or x%4 == 0 and x%100 != 0:         print '%s 是闰年' % x     else:         print '%s 是平年' % x year = raw_input('Please a year number:') year = int(year) f(year)

判断输入的年份是否为闰年

#!/usr/bin/env python import sys def judge_year():     while True: try:     year = raw_input('please input a year: ') except (EOFError,KeyboardInterrupt):     print '\n'     sys.exit()         if len(year) == 0:     print 'input nothing,please try ag

python判断是否是闰年

判断给的年是否是闰年! #!/usr/bin/env python ye = int(raw_input('Please enter the year:')) if ye % 100 == 0:         if (ye/100) % 4 == 0:                 print "your inputing is a leap year!"         else:                 print "your inputing is not 

闰年测试和对输入的非法判断

1问题描述 输入一个测试用例,判断输入用例是否为闰年 2方法使用 这里用到两个函数方法第一个方法由于都在if语句中判断,所以不好测试,第二个方法可以更加明确的判断 3具体代码 #include<stdio.h> #include<sstream> #include<string> using namespace std; void judge(int year){ bool b; if (year % 4 == 0) b=true; if (year % 100 ==

判断年份是否为闰年及非法数据的处理

一.问题描述 判断输入的年份是否为闰年 二.功能实现 在输入栏中输入年份,点击确认按钮,若年份为闰年,则显示“您输入的年份是闰年”,如年份非闰年,则显示“您输入的年份不是闰年” 三.代码实现 <html> <head> <script type="text/javascript"> function test(){ var input1=document.getElementById('input1').value; if input1%400==0

php之实战项目--年份判断是否为闰年

实现效果: 实现代码: <html><head><meta charset="utf8"></head><body><table border="1" align="center" width="450" height="101" cellpadding="1" cellspacing="1" bgco