Originally posted by Linda Pan:
The answer: ((2) + (2) + (3)) --> 7
How does one arrive at 3?
[ March 11, 2003: Message edited by: Linda Pan ]
Originally posted by Linda Pan:
that '+ + k' is the same as a postfix
So what is the + + operator? There is no such thing. This statement is simply two unary operators next to one another.
Originally posted by Linda Pan:
that '+ + k' is the same as a postfix
(d) The expression "++k + k++ + + k" is parsed as ((++k) + (k++)) + (+k) -> ((2) + (2) + (3)), therefore the program prints 7 when run.
Regards, Manish
SCJP 1.4
sharana
"Walking on water and building IT Architecture from <br />specification are easy if and only if both are frozen"
sharana
Francis Siu
SCJP, MCDBA
Francis Siu
SCJP, MCDBA
Originally posted by Anu Pasricha:
Parsing in Java takes place from left to right.
Paragraph 1 of chapter 15.7 in Java Language Specification ( http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#4779 ):
The Java programming language guarantees that the operands of operators appear to be evaluated in a specific evaluation order, namely, from left to right.
Francis Siu
SCJP, MCDBA
Francis Siu
SCJP, MCDBA
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |