This is a java program to check a year is leap year or not.
lea year come after 4 years next. like 2020 is a leap year after 2024 will be leap year.

Go to the java series.: https://browncodeit.blogspot.com/p/java-programs.html

Source Code:

  1. public class LeapYearDemo {
  2. public static void main(String[] args) {
  3. try (
  4. Scanner input = new Scanner(System.in)) {
  5. int yr;
  6.  
  7. System.out.print("Enter the year: ");
  8. yr = input.nextInt();
  9.  
  10. if(yr%400==0 ||(yr%100 != 0 && yr%4==0)) {
  11.  
  12. System.out.println("This is Leapyear.");
  13. }
  14. else {
  15. System.out.println("this is not leapyear.");
  16. }
  17. }
  18. }
  19. }


Output:

Enter the year: 2020
This is Leapyear.

Enter the year: 1589
this is not leapyear.

0 comments:

Post a Comment