public static void main(String[] args) {
int x = 10;
x = x++;
x = x++;
x = x++;
System.out.println(x);
}
Why is the output 10 when the expected output is 13?
Post increment operator x++
returns the original value of x
. Therefore x=x++
assigns the old value of x
back to x
.
This is probably what you weant to do
public static void main(String[] args) {
int x = 10;
x++;
x++;
x++;
System.out.println(x);
}