“Metoda Java Year Year” Kod odpowiedzi

Program LEAP Year w Javie

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 Lata

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)

Metoda Java Year Year

public class LeapYear {

    // Method to check leap year
    public static void checkLeapYear(int year) {
        if (year % 400 == 0) {
            System.out.println(year + " is a leap year.");
        } else if (year % 100 == 0) {
            System.out.println(year + " is not a leap year.");
        } else if (year % 4 == 0) {
            System.out.println(year + " is a leap year.");
        } else {
            System.out.println(year + " is not a leap year.");
        }

    }

    public static void main(String[] args) {
        // Examples
        checkLeapYear(1998);
        checkLeapYear(2000);
    }
}

Output:

1998 is not a leap year.
2000 is a leap year.
codelearner

Odpowiedzi podobne do “Metoda Java Year Year”

Pytania podobne do “Metoda Java Year Year”

Więcej pokrewnych odpowiedzi na “Metoda Java Year Year” w Java

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu