• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

if (a==b==c)

 
David Mroczkowski
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure this basic is as do-re-mi, but here's another question that I need some help with...
boolean a = false;
boolean b = false;
boolean c = true;
if ( a==b==c){
System.out.println("true");
} else {
System.out.println("false");
}
This prints "true". Yes?
Then is the following prints the same?
boolean a = false;
boolean b = false;
boolean c = true;
if ((a==b)==c){
System.out.println("true");
} else {
System.out.println("false");
}
I'm preparing for the certification and sometimes the simple ones throw me.
Which way would be the preferred way?
Appreciate it,
d
 
Wirianto Djunaidi
Ranch Hand
Posts: 210
Ruby Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both will be the same, because the rule of precedence the first program will be the same as the second one.
Of course it will be more user readable in the second one.
 
David Mroczkowski
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank Ryo!
Sometimes you just need confirmation.
d
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic