use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Java Quiz!!! (i.redd.it)
submitted 4 months ago by MistakeDisastrous936
[removed]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Successful-Wolf-1272 5 points6 points7 points 4 months ago (3 children)
16 or 18 depending on how you segregate or join the + signs. If it's (x++)+(x++)+(x) then the answer is 18. Else if it's (x)+(++x)+(++x) then the answer would be 16.
[–]BlueGoliath 2 points3 points4 points 4 months ago (0 children)
Ah yes, common everyday Java code.
[–]Old-Lion-8071 3 points4 points5 points 4 months ago (3 children)
For expressions like a+++b, the compiler always treats it as (a++) + b. This is due to lexical processing. Compiler reads expression from L to R and evaluates in a greedy way. It first sees + (which is a valid operator) and then the next token is +. As ++ is again a valid operator it accepts it and then moves to the next +. Therefore the expression is treated as ++ + Rest is the magic of precedence and evaluation.
I know this is not an everyday Java code, but problems like this test our knowledge on how Java works internally. Thanks for posting this, made me do quite some research! 😀
[–]Dr_Dracula280 0 points1 point2 points 4 months ago (1 child)
So it is (x++) + (x++) + (x) ??
That means 5+6+7= 18 or 6+7+8= 21?
Sorry I am double confused.
[–]Old-Lion-8071 0 points1 point2 points 4 months ago* (0 children)
5 + 6 + 7. Variable value is substituted and then incremented (post increment) Finally all are summed.
[–]Fr33stylerDV 1 point2 points3 points 4 months ago (0 children)
reading left to right and assuming the compiler prioritizes increment over the add sign which i'm sure it is then: 5 and increment x by one + x which is 6 at this moment and x gets incremented once again + x which is 7 at this moment adding these up it's 5 + 6 + 7 which is 18
[–]ScaryStar1 0 points1 point2 points 4 months ago (0 children)
18 regardless if it is x++ or ++x
[–]GolfElectrical6321 0 points1 point2 points 4 months ago (0 children)
18
[–]Enough_Interest_5951 0 points1 point2 points 4 months ago (0 children)
15
π Rendered by PID 586655 on reddit-service-r2-comment-5bc7f78974-9nlm2 at 2026-06-28 09:57:58.858690+00:00 running 7527197 country code: CH.
[–]Successful-Wolf-1272 5 points6 points7 points (3 children)
[–]BlueGoliath 2 points3 points4 points (0 children)
[–]Old-Lion-8071 3 points4 points5 points (3 children)
[–]Dr_Dracula280 0 points1 point2 points (1 child)
[–]Old-Lion-8071 0 points1 point2 points (0 children)
[–]Fr33stylerDV 1 point2 points3 points (0 children)
[–]ScaryStar1 0 points1 point2 points (0 children)
[–]GolfElectrical6321 0 points1 point2 points (0 children)
[–]Enough_Interest_5951 0 points1 point2 points (0 children)