A given year is said to be a leap year if it is divisible by 4 and at the same time not by 100.
Or It is divisible by 400.
Ex:- 2100 ( divisible by 4 and 100 both ) ✖ Not a leap year
2020 ( divisible by 4 and not divisible by 100 ) ✔
Leap year
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import java.util.Scanner; public class Prime{ public static void main(String []args){ Scanner sc = new Scanner(System.in); int year = sc.nextInt(); System.out.print(checkLeapYr(year)); } public static boolean checkLeapYr(int year){ if( ( (year%4==0)&&(year%100!=0) ) || (year%400==0)) return true; return false; } } |
Python
def checkLeapYr(year): if ( (year%4==0) and (year%100!=0) ) or (year%400==0): return True return False year = int(input()) print(checkLeapYr(year))