Advertisement
sohailoo

Untitled

May 21st, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. A year is a leap year if it is divisible by 4. But if the year is divisible by 100, it is a leap year only when it is also divisible by 400.
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class LeapYear {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner reader = new Scanner(System.in);
  9.         System.out.print("Type a year: ");
  10.         int year = Integer.parseInt(reader.nextLine());
  11.         int leap1 = year % 4;
  12.         int leap2 = year % 100;
  13.         int leap3 = year % 400;
  14.         if (leap1 == 0 || ((leap2 == 0) && (leap3 == 0))) {
  15.             System.out.println("The year is a leap year.");
  16.         } else {
  17.             System.out.println("The year is not a leap year");
  18.         }
  19.  
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement