• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

EqualsEx

 
Ranch Hand
Posts: 182
Java
  • 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.
 
Ranch Hand
Posts: 580
Eclipse IDE
  • 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

 
Ranch Hand
Posts: 249
  • 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
  • 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
  • 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
  • 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.
 
Ranch Hand
Posts: 30
  • 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..
 
She'll be back. I'm just gonna wait here. With this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!