Hi I have the following code:
boolean result = someexpression();
if(!result)
{
System.out.println("False...");
}
if (result);
{
System.out.println("True");
}
It prints both (False and true)
I also tried using things like
if(result==true)
but that doesnt seem to do the trick. No matter what the value of the variable it just enters the condition.?? I am using eclipse and this only happens at a specific portion.
Remove the
;at the end of this line.With the
;, it means “ifresultistrue, then do nothing”. The block that contains the next statement isn’t part of theifand will always be executed. It’s exactly the same as this: