• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

JQPlus Trial Version - Quest. #33

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the code:
boolean b1 = false;
boolean b2 = false;
if (b2 = b1 != b2)
{
System.out.println("true");
} else
{
System.out.println("false");
}
The output for this code is: false. I'm confused as to why the expression b1 != b2 is evaluated first. What is the logic here?
Mansi
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your expression != is a boolean comparison operator and = is a assignment operator. Since the precedence of != is greater than =, the expression b1!=b2 will be evaluated first.
ie., b2 = (b1 != b2)
b2 = (false != false)
b2 = false
 
Mansi Vyas
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the info.
By the way, do u know where I can get information on the rules for precedence?
Thanks.
Mansi
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mansi Vyas:
Thanks for the info.
By the way, do u know where I can get information on the rules for precedence?
Thanks.
Mansi


Read Operators Precedence Chart.
You don't have to memorize it for the exam though.
 
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic