• Post Reply Bookmark Topic Watch Topic
  • New Topic

Increment and decrement operators  RSS feed

 
Miles Davis
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this question: If x has the value 10 and so does y, then what is the value of (x ++) * (-- y)? I put this through Java, and I get back 90. However, the answer to the question (apparently) is 99. What am I doing wrong, if anything?
 
Tim Cooke
Marshal
Posts: 4041
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did the question come from?
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two options here:
1. Answer is incorrect
2. Question you copied/pasted is with omitted important parts, so you assumed it wrongly

Post exact question and possible answers.
 
Miles Davis
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got the question from a homework problem. The answer says "11 * 9." I did post the question in its entirety. I'll have to let my teacher know that the answer book gives the incorrect answer. Thanks!
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[edit]: well, if the question is exactly as you posted and the answer as you stated - then it is incorrect.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree: the operations of those operators is strictly defined in the Java® Language Specification and the expression you posted will evaluate to 90.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!