Why does this return true?
String b = "(5, 5)";
String a = "(7, 8)" ;
if(a.equals(b));
{
System.out.printf("Somehow \"%s\" and \"%s\" are the same" ,a,b);
}
Output:
Somehow "(7, 8)" and "(5, 5)" are the same
Why does this return true?
String b = "(5, 5)";
String a = "(7, 8)" ;
if(a.equals(b));
{
System.out.printf("Somehow \"%s\" and \"%s\" are the same" ,a,b);
}
Output:
Somehow "(7, 8)" and "(5, 5)" are the same
Your code is equivalent to:
if(a.equals(b)) { }
{
System.out.printf("Somehow \"%s\" and \"%s\" are the same" ,a,b);
}
So the print statement in a block that'll be always executed regardless of the condition, since the body of the if doesn't include that statement.
See the JLS - 14.6. The Empty Statement:
An empty statement does nothing.
EmptyStatement:
;Execution of an empty statement always completes normally
You have ; after your if statement.
use:
if(a.equals(b)) {
System.out.printf("Somehow \"%s\" and \"%s\" are the same" ,a,b);
}
Take a look at this answer.
if(a.equals(b));<-----
You have an extre ; there and statements ends there.
That's like writing
if(a.equals(b));
and a block here
{
System.out.printf("Somehow \"%s\" and \"%s\" are the same" ,a,b);
}
So get rid of that extra ;
static { ... }.