Answers for "leap year program in java"

7

check leap year in java

import java.util.Scanner;
public class LeapYear {
   public static void main(String[] args){
      int year;
      System.out.println("Enter an Year :: ");
      Scanner sc = new Scanner(System.in);
      year = sc.nextInt();

      if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0))
         System.out.println("Specified year is a leap year");
      else
         System.out.println("Specified year is not a leap year");
   }
}
Posted by: Guest on May-07-2020
5

leap year program in java

public static boolean isLeapYear(int year) {
  if (year % 4 != 0) {
    return false;
  } else if (year % 400 == 0) {
    return true;
  } else if (year % 100 == 0) {
    return false;
  } else {
    return true;
  }
}
Posted by: Guest on June-30-2020
2

java leap years

public static boolean isLeapYear(int year) {
  if (year % 4 != 0) {
    return false;
  } else if (year % 100 != 0) {
    return true;
  } else if (year % 400 != 0) {
    return false;
  } else {
    return true;
  }
}
Posted by: Guest on January-25-2021
1

java leap year expression

(year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0))
Posted by: Guest on January-25-2021
0

leap year checker java

public class LeapYear {

    public static void main(String[] args) {

        int year = 1900;
        boolean leap = false;

        if(year % 4 == 0)
        {
            if( year % 100 == 0)
            {
                // year is divisible by 400, hence the year is a leap year
                if ( year % 400 == 0)
                    leap = true;
                else
                    leap = false;
            }
            else
                leap = true;
        }
        else
            leap = false;

        if(leap)
            System.out.println(year + " is a leap year.");
        else
            System.out.println(year + " is not a leap year.");
    }
}
Posted by: Guest on March-22-2020
0

Leap year or not program in java using if-else

import java.util.Scanner;public class Main{public static void main(String[] args){int year;System.out.println("Enter the year");Scanner sc = new Scanner(System.in);year = sc.nextInt();if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0))System.out.println("it is a leap year");elseSystem.out.println("it is not a leap year");}}
Posted by: Guest on June-12-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language