This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EqualsEx

 
Balaji Bang
Ranch Hand
Posts: 182
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


OUTPUT : 1 false 2 true false 5 false 6 false

My Doubt is why the string " 3 " ," 4 " in line 1 are not printing and also totally we have 6 boolean tests but why I am getting only 5 boolean literals.
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First i was surprised to see the result .... then i felt funny ..... it happens
check the brackets in the LINE one

 
Dawn Charangat
Ranch Hand
Posts: 249
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This will work fine if you change "Line 1" to

System.out.print(" 3 " + (s2 == s3) + " 4 " + (s2 == s4));//Line 1

Dawn.
 
Balaji Bang
Ranch Hand
Posts: 182
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya I replaced . Now I am able to get the Strings " 3" and " 4 " in the output. But still i didn't get the logic in the brackets(). What happens if there is no bracket ???
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
" 3 " + (s2 == s3) + " 4 " + s2
this part of the statement results to
"sfalse4java"----------- which is a string.
Now you are comparing this... it would be like this
("sfalse4java")==s4
 
Balaji Bang
Ranch Hand
Posts: 182
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ohhhhhhhhhhhhhhh my god!!.

Day by day I am learning new things and forgetting old things.......
Thank you James.
 
mohan rajv
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this s operator precedence..
== operator has less priority than +
and the expressions are evaluated from left to right..
so in Line1 is evaluated as false.
the expression is similar to :
(" 3 " + (s1==s3) + " 4 "+ s2) == s4
the result of this expression is false..
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic