• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String comparison

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Can anybody tell me why the following programme is showing me compile time error?



Thanks in advance
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well Pawan it is happening because precedence of + is higher than ==. Modify your code as

System.out.print((s1==s2) +"," + (s2==s3) +"," + (s1==s3) +"," + (s2==s4)+"," + (s3==s4));
 
Pawan Arora
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ankit
 
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pawan,

Hope you got this code from my exam simulator, ExamLab
(Question no: 54 in Diagnostic exam)

There is a built-in explanation available for this question in the simulator software, didn't you read it?

Anyway, please read and understand the copyright rule in JavaRanch. According to this rule, you CAN copy and paste a question here, but you must specify the location where did you copy it from.

Now it's ok, but please follow this rule, when you post a question again.


Note: All of the questions and explanations in this simulator were copywritten.

 
reply
    Bookmark Topic Watch Topic
  • New Topic