Write a Java program that takes a year from user and print whether that year is a leap year or not


Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. import java.util.Scanner;
  2. public class JavaExcercise {
  3.  
  4.  
  5. public static void main(String[] args)
  6. {
  7. Scanner in = new Scanner(System.in);
  8.  
  9. System.out.print("Input the year: ");
  10. int year = in.nextInt();
  11.  
  12. boolean a = (year % 4) == 0;
  13. boolean b = (year % 100) != 0;
  14. boolean c = ((year % 100 == 0) && (year % 400 == 0));
  15.  
  16. if (a && (b || c))
  17. {
  18. System.out.println(year + " is a leap year");
  19. }
  20. else
  21. {
  22. System.out.println(year + " is not a leap year");
  23. }
  24. }
  25. }

Result

java techstudy.org

     





Related Topics




Popular Posts