• 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
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Sybex OCP Java 11

 
Greenhorn
Posts: 8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im 15 years old and want to know if I paid attention to the explanations about unary operators and their precedence.

Little part of the table

1.Post increment (expression++/--)
2. Pré increment (++/--expression)

In the example(page 84 and 85) -> int lion; int tiger = ++lion * 5 / lion--;

The book explains that, first java works above pre increment and after post increment, but its not!

Should be something like -> First post increment and after pre increment, cause post increment has more precedence, or the order of the table is wrong, or in this case java start left to right?

Thanks!!!
 
Marshal
Posts: 69411
276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

No, precedence isn't the thing. Java® expressions are always evaluated as they are written, left to right, taking () and precedences and associativity into account. The left to right rule takes precedence over precedences.
 
Nicholas Barbosa
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!!
 
Do not meddle in the affairs of dragons - for you are crunchy and good with ketchup. Crunchy tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic