Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Monday, October 17, 2016

How to verify if a boolean is true or false

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 by Gjhuizing for How to verify if a boolean is true or false


Replace

if (isLeapYearJulian == true)  

with

if (isLeapYearJulian(age))  

Answer by pmcevoy12 for How to verify if a boolean is true or false


I think you want this

public static int daysInYearGregorian(int year) {      boolean isLeapYearGregorian = isLeapYearGregorian(year);      if (isLeapYearGregorian) {          return 366;      }      else {          return 365;      }  }`  

or more simply

public static int daysInYearGregorian(int year) {      if (isLeapYearGregorian(year)) {          return 366;      }      else {          return 365;      }  }`  

or even more simply

public static int daysInYearGregorian(int year) {      return isLeapYearGregorian(year) ? 366 : 365;  }`  

Answer by Anubhav Dhawan for How to verify if a boolean is true or false


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

and

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

I suppose that's what you are trying to do here

Answer by Zbynek Vyskovsky - kvr000 for How to verify if a boolean is true or false


For testing boolean put it directly in the if:

if (boolVariable) {      ...  }  

However yhe problem here is different - there should be actually function call so the parenthesis and parameters are needed:

if (isLeapYearJulian(year)) {      ...  }  

Answer by Sci Prog for How to verify if a boolean is true or false


The problem was that you did not call the functions (see answer by http://stackoverflow.com/users/1361491/gjhuizing).

Also, you could simplify your code:

public static boolean isLeapYearJulian(int year) {    return (year % 4 == 0);  }    public static boolean isLeapYearGregorian(int year) {    if (year % 400 == 0) return true;    if (year % 100 == 0) return false;    return (year % 4 == 0);  }    // EXERCICE 2 QUESTION 2                                public static int daysInYearJulian(int year) {    return isLeapYearJulian(year) ? 366 : 365;  }    public static int daysInYearGregorian(int year) {    return isLeapYearGregorian(year) ? 366 : 365;  }  

Answer by pankaj for How to verify if a boolean is true or false


isLeapYearjulian is not a variable here,
its an identifier that refers to a function name:
Correct it to:

 public static int daysInYearJulian(int year) {          if (isLeapYearJulian(year) == true) {              return 366;          }          else {              return 365;          }      }  

Answer by YorickIsTheBest for How to verify if a boolean is true or false


First of all, I want to tell you that you have an accent mark (`) at the very bottom of your code. Anyways, the only thing I can see wrong with this is t

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

Anyways, the only thing I can see wrong with this is that your last two methods,

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

and

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

is that they are each looking for, and trying to check the value of VARIABLES named 'isLeapYearGregorian' and 'isLeapYearJulian.' If you want your program to check the value that your the methods return, you must 'call' your method by using parenthesis like so:

isLeapYearJulian()  

and

isLeapYearGregorian()  

Your code should work if you fix your if else statements.


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

Related Posts:

0 comments:

Post a Comment

Popular Posts

Fun Page

Powered by Blogger.