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 :: area of circle in java 
Java :: java for each 
Java :: java calendar hour vs hour of day 
Java :: java get sub array 
Java :: object to string in java 
Java :: android activity read intent extra 
Java :: how to add elements to an array in java dynamically 
Java :: java scanner 
Java :: java code samples 
Java :: java insert into arraylist 
Java :: java selenium send keys integer 
Java :: how to calculate exponential in java 
Java :: java jframe actionlistener 
Java :: java docstring javadoc 
Java :: convert string to character array 
Java :: kotlin variable in string 
Java :: convert int[] to list java 
Java :: AmazonS3ClientBuilder 
Java :: how to detect device javascirpt 
Java :: how to create relative layout in android studio 
Java :: string to float java 
Java :: define a list java 
Java :: Java for Keyword 
Java :: Caused by: java.lang.RuntimeException: No installed build tools found. Install the Android build tools version 19.1.0 or higher. 
Java :: modal css react 
Java :: java exception message 
Java :: java length of matrix 
Java :: java csv line split 
Java :: assert throws exception java 
Java :: get year month day from date string java 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =