Advertisement
newbninja

Leap Year Finder

Oct 16th, 2023
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class LeapYearChecker {
  4.     public static void main(String[] args) {
  5.         // Create a Scanner object to read input from the user
  6.         Scanner scanner = new Scanner(System.in);
  7.        
  8.         // Prompt the user to enter a year
  9.         System.out.print("Enter a year: ");
  10.        
  11.         // Read the year from the user
  12.         int year = scanner.nextInt();
  13.        
  14.         // Close the Scanner
  15.         scanner.close();
  16.        
  17.         // Check if the year is a leap year
  18.         boolean isLeapYear = false;
  19.        
  20.         if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
  21.             isLeapYear = true;
  22.         }
  23.        
  24.         // Display the result
  25.         if (isLeapYear) {
  26.             System.out.println(year + " is a leap year.");
  27.         } else {
  28.             System.out.println(year + " is not a leap year.");
  29.         }
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement