TierOne TierOne - 1 month ago 6
Java Question

How to verify if a boolean is true or false

First of all, I apologize about my english. When it comes to explaining ideas, problems linked to programming I still have troubles to be clear about what is wrong and I want.

The code :

public static boolean isLeapYearJulian(int year) {
// Modifier le code ci-dessous
if (year % 4 == 0) {
return true;
}
else {
return false;
}

}

public static boolean isLeapYearGregorian(int year) {
// Modifier le code ci-dessous
if ((year % 4 == 0) && (year % 100 != 0) || (year % 4 == 0) && (year % 100 == 0) && (year % 400 == 0)) {
return true;
}
else {
return false;
}

}

// EXERCICE 2 QUESTION 2
public static int daysInYearJulian(int year) {
// Modifier le code ci-dessous
if (isLeapYearJulian == true) {
return 366;
}
else {
return 365;
}
}

public static int daysInYearGregorian(int year) {
// Modifier le code ci-dessous
if (isLeapYearGregorian == true) {
return 366;
}
else {
return 365;
}
}`


The thing is that I would like to see if isLeapYearGregorian and isLearYearJulian are true or not to know if the year is bisextile. But (yes I'm new, very new to programming) I just can't remember to test a boolean ... So with a lot of a shame, I'm asking help to you guys ... Thanks in advance.

By the way, the terminal is returning this :

Calendar.java:47: error: cannot find symbol
if (isLeapYearJulian == true) {
^
symbol: variable isLeapYearJulian
location: class Calendar
Calendar.java:57: error: cannot find symbol
if (isLeapYearGregorian == true) {
^
symbol: variable isLeapYearGregorian
location: class Calendar
2 errors

Answer

Replace

if (isLeapYearJulian == true)

with

if (isLeapYearJulian(age))
Comments