Question 186 / 297:  What is the result of compiling and running the following code?
public static void main(String[] args) {

int x = 0, y = 0;

x = 5 + y++;

System.out.print(x + "" + y);

x = 0;

y = 0;

x = 5 + ++y;

System.out.print(x + "" + y);

}

A  6161
B  671
C  5161
<< First < Previous Next > Last >>
Explanation:

at line 3, the addition is done first and after finish, increment y

at line 8 , increment y first and then do the arithmetic operation

Exam Home Page
Ask
Jugnu Khan
Start Quiz
Marion Cabalfin
Start Quiz
Copy and paste the following HTML code into your website or blog.
<iframe src="https://www.jobilize.com/embed/java-certification-questions" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>