This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • 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

Possible errata OCP Java SE 11 study guide - Precedence query

 
Greenhorn
Posts: 11
2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 85, regarding the code involving the lion, Line 1 in the 2nd paragraph reads, "First, lion is incremented and then returned to the expression, ", following which, it is mentioned that lion is decremented.

Is this an incorrect interpretation of the precedence of the post and pre-unary operators, or is the precedence of these operators ignored when they appear in the same line of arithmetic code and the compiler reads from left to right anyway?

xoxoxo
 
Marshal
Posts: 68110
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain more about your question. I think you may have gone down with the common misunderstanding that precedences of operators equate to order of execution.
 
author & internet detective
Posts: 39890
798
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code being discussed here is:


On page 81, we have the order of precedence table. Where we note that x++ is a higher precedence than --x.

So you are correct that the explanation should use that order. Good catch. I can't believe nobody noticed that in the OCA 8 book!
 
Campbell Ritchie
Marshal
Posts: 68110
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you get an overflow error, the answer should always be 5.
 
Amateurs built google. Professionals built the titanic. We can't find the guy that built 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!