首先,我對我的英文表示歉意。當談到解釋想法時,與編程相關的問題我仍然有困難要清楚哪些問題和我想要的。如何驗證布爾值是真是假
代碼:
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;
}
}`
的事情是,我想看看是否isLeapYearGregorian和isLearYearJulian是真的還是不知道,如果今年是bisextile。但是(是的,我是新的,編程非常新)我只是不記得測試一個布爾值......所以有一個很遺憾的是,我向你們求助......在此先感謝。
順便提一下,終端返回此:
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
關於您的問題標題:如何驗證布爾值是true還是false - 使用if塊。 –
您正在調用方法而不使用括號或傳入參數。編譯器錯誤信息會告訴你在哪裏。投票結束作爲印刷錯誤。 –
@TierOne隨意標記[我的答案](http://stackoverflow.com/questions/40064006/how-to-verify-if-a-boolean-is-true-or-false/40064059#40064059)爲接受(綠色標記),如果它解決了你的問題:) –