Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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;
  }
}
Comment

java leap year expression

(year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0))
Comment

java leap year

  public static void main(String[] args) {
        int year = 2005;

        if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))){
            System.out.println(year+" leap year");
        }else {
            System.out.println(year+" not a leap year");
        }
    }
Comment

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;
  }
}
Comment

java check if year is leap

      boolean isLeap =  new GregorianCalendar().isLeapYear(2020);
      //returns true
Comment

java leap years


public static boolean isLeapYear(int year) {
  Calendar cal = Calendar.getInstance();
  cal.set(Calendar.YEAR, year);
  return cal.getActualMaximum(Calendar.DAY_OF_YEAR) > 365;
}

Comment

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");}}
Comment

PREVIOUS NEXT
Code Example
Java :: initial data for list java 
Java :: assert throws exception java 
Java :: No Java executable found in current PATH: /bin:/usr/bin:/sbin:/usr/sbin 
Java :: on selected item changed listview javafx 
Java :: javafx change textfield background color 
Java :: JAVA Display Sum of n Natural Numbers 
Java :: spring boot save file to static folder 
Java :: collatz conjecture 
Java :: how to change theme of app in android studio programmatically 
Java :: navigate to another activity in android 
Java :: java median of list 
Java :: isnull java 
Java :: arrays.aslist 
Java :: android application subclass 
Java :: react The href attribute is required for an anchor to be keyboard 
Java :: java Program for Sum of the digits of a given number 
Java :: runtime intalize array in java 
Java :: hadoop-master error java_home is not set and could not be found 
Java :: get string of radio button in android 
Java :: glide library in android studio 
Java :: difference between object and class 
Java :: BST in java 
Java :: login and logout react native and firebase 
Java :: java printf 
Java :: java program for multiplication table 
Java :: palindrome find in java 
Java :: java sort a Map by keys reverse descending order 
Java :: change size of array java 
Java :: get string from int java 
Java :: assert multiple junit 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =