Advertisement
damoncard

Leap Year

Sep 4th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. import java.util.Scanner; // import Scanner method
  2. public class (Name) // This is your file name
  3. {
  4.   public static void main(String [] args) // main method (whatever other method do, this method will be the end of your code)
  5.   {
  6.     System.out.print("What is your year?");
  7.     Scanner in = new Scanner (System.in);
  8.     int year = in.nextInt(); // Scan your number (it can be any number except number with floating points)
  9.     System.out.print("The answer is "+isLeapYear(year));
  10.   }
  11.   public static boolean isLeapYear(int year) // new method (sub-method)
  12.   {
  13.     if (year%4 == 0 && year%100 != 0 || year%400 == 0) // check about year
  14.     {
  15.       return true; // if year is true in above condition this will be represent
  16.     } else { // whatever that not make the above condition true
  17.       return false;
  18.     }
  19.   }
  20. }
  21. // PS. %(mod) is operator
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement