• 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

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.
 
I'm doing laundry! Look how clean this tiny ad is:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic