Leap Year - Coder's point

Saturday, June 1, 2019

Leap Year

 
import java.util.Scanner; public class LeapYear { boolean isLeapYear(int y) { if(y%100==0) { if(y%400==0) { return true; } } else if(y%4==0) { return true; } return false; } static void main() { Scanner in = new Scanner(System.in); System.out.println("Enter a year"); int y=in.nextInt(); if(new LeapYear().isLeapYear(y)) { System.out.println("Leap Year"); } else { System.out.println("Not a Leap Year"); } } }
OUTPUT:
Enter a year
2019
Not a Leap Year
Enter a year
2016
Leap Year

No comments:

Post a Comment