实例1 -- 判断输入年份是否为闰年

闰年的条件: 能被4整除且不能被100整除的为闰年或能被400整除 则为闰年

java写法:

 1 import java.util.*; 
 2   
 3 public class LeapYear{
 4     public static void main(String[] args){
 5         Syste.out.println("请输入年份:");
 6         Scanner sc = new Scanner(System.in);
 7         
 8         int year = sc.nextInt();
 9         if(year%4 == 0 && year%100 != 0 || year%400 == 0){ 
10             System.out.println(year + "年是闰年");
11         }else{
12             System.out.println(year + "年非闰年");
13         }
14  
15     }
16  }                       

Python写法:

1 #coding=utf-8
2 
3 year = int(raw_input('请输入年份:'))
4 if year%4 == 0 and year%100 != 0 or year%400 == 0:
5   print year,'年是闰年'
6 else:
7   print year,'年非闰年'
原文地址:https://www.cnblogs.com/dtest/p/4127289.html