• 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

Sybex OCP Java 11

 
Ranch Hand
Posts: 45
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic