sohailoo

Untitled

May 22nd, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. Question: 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.        
  10.         System.out.print("Type a year: ");
  11.         int year = Integer.parseInt(reader.nextLine());
  12.         int leap1 = year % 4;
  13.         int leap2 = year % 100;
  14.         int leap3 = year % 400;
  15.         if (((leap1==0) && (leap2!=0))||(leap3==0)){
  16.             System.out.println("The year is a leap year.");
  17.  
  18.         }else {
  19.             System.out.println("The year is not a leap year.");
  20.         }
  21.        
  22.        
  23.  
  24.     }
  25. }
Add Comment
Please, Sign In to add comment