Count of Leap Years in a given year range | Java implementation to find the count of leap years in given range of the year ; Function to calculate the number of leap years in range of ( 1 , year ) ; Function to calculate the number of leap years in given range ; Driver Code
class GFG { static int calNum ( int year ) { return ( year / 4 ) - ( year / 100 ) + ( year / 400 ) ; } static void leapNum ( int l , int r ) { l -- ; int num1 = calNum ( r ) ; int num2 = calNum ( l ) ; System . out . print ( num1 - num2 + "NEW_LINE"); } public static void main ( String [ ] args ) { int l1 = 1 , r1 = 400 ; leapNum ( l1 , r1 ) ; int l2 = 400 , r2 = 2000 ; leapNum ( l2 , r2 ) ; } }