• Post Reply Bookmark Topic Watch Topic
  • New Topic

Expression involving multiple operators  RSS feed

 
Tresa P Anthony
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,



This prints 15. Please explain how (using parenthesis if possible)

Thanks
Tresa
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you experiment with the code yourself and see what happens? Add parentheses, and see what happens. For example:

This prints 12 instead of 15.
And this:

prints 15.

Just try it out and discover for yourself what happens exactly. By playing with it and finding it out yourself, you learn more then when somebody else gives you the answer directly.

p.s. Please, never write code like this in a real application. It's fine as a brain teaser, to learn how operators work in Java, but in a real application this will only confuse programmers who need to maintain the code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!