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 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 :: read file using scanner in java 
Java :: convert object to map scala 
Java :: java contains password input 
Java :: spring create bean only if another bean does not exists 
Java :: java getdeclaredfield private field 
Java :: java ldaps certificate self signed 
Java :: convert long to date in java 
Java :: java number of days between dates 
Java :: What AJAJ stand for 
Java :: java string to char array 
Java :: jbutton actionlistener 
Java :: How to find a target element within a search pool using binary search? 
Java :: java test if a string is a int 
Java :: Integrity check failed: java.security.NoSuchAlgorithmException: Algorithm HmacPBESHA256 not available jks 
Java :: lakshya 
Java :: count the number of words in a string java 
Java :: java key pressed 
Java :: android action key 
Java :: spring data rest format time and date 
Java :: big integer input in java 
Java :: map java get first key 
Java :: how to stop timer in java 
Java :: java real random 
Java :: java string contains number 
Java :: formartted string java 
Java :: gradle require java version 
Java :: compare date with current date in android 
Java :: add certificate to java truststore 
Java :: how to get the last element of array in java 
Java :: android fragment fullscreen 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =