• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Operator Precedence.

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers!
Hey, I've a basic doubt.
I've code like this.
This compiled, and executed prints "0.0".

As far as i know, multiplication operator (*) precedes over divsion operator (/).

So why doesn't the above code doesn't produce Arithmetic Exception ??
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have not mentioned what raise() is returning.

Regarding the operator precedence
both * and / has same priority.
So always evaluate your expression from left to right
Assuming raise() is returning 0, your expression
will first evaluate currentSalary / 100 this gives you 1.0
and then multiplication by 0 , so results is 0.0
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Palla

As far as i know, multiplication operator (*) precedes over divsion operator (/).



Nope. They are equal precedence and are evaluated left to right.



produces 3.
See K&B Exam Watch Pg. 278.

Aloha,
Doug

-- Nothing is impossible if I'mPossible
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !!!
Take a look to Operator Precedence
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
according to me 100 will get multiply with the return value if . and then multiply with
 
palla sridhar
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Doug!
Doesn't your eg. give an answer of 9.

Please let me know!!
 
Doug Slattery
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Palla,

Originally posted by palla sridhar:
Hey Doug!
Doesn't your eg. give an answer of 9.

Please let me know!!



Yes, it's supposed to be 9. My bad. Sometimes my head is a couple pages ahead of my fingers. I was thinking 9, but 3 came out .

Aloha,
Doug

-- Nothing is impossible if I'mPossible
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!