“Java Leap Year” Réponses codées

Programme d'année de saut à 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;
  }
}
Successful Shrike

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;
  }
}
Merlin4 (ranken)

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

Java vérifie si l'année est leap

      boolean isLeap =  new GregorianCalendar().isLeapYear(2020);
      //returns true
Kirk-Patrick Brown

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

Tough Tapir

Leap an ou non programme en Java en utilisant 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");}}
Helpless Hawk

Réponses similaires à “Java Leap Year”

Questions similaires à “Java Leap Year”

Plus de réponses similaires à “Java Leap Year” dans Java

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code