Pre-increment vs Post-increment Operators
What is printed when the following program is executed?
public class IncrementTest {
public static void main(String[] args) {
int x = 5;
int y = x++;
int z = ++x;
System.out.println("x: " + x + ", y: " + y + ", z: " + z);
}
}
A
x: 6, y: 5, z: 6
B
x: 7, y: 6, z: 7
C
Compilation Error
D
x: 7, y: 5, z: 7
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | ntgamja1 | 1 | 1 | 0m 36s | 64 |
| #2 | 6test6ing6 | 0 | 1 | 0m 00s | -10 |
| #3 | patrickmeijer009 | 1 | 4 | 1m 40s | -30 |
| #4 | bommasam000 | 1 | 4 | 3m 33s | -143 |
| #5 | lsj08030922 | 0 | 1 | 20m 15s | -1,225 |
Items per page:
10
1 – 5 of 5
APFIVE