Exercise B1
Java Fundamentals exercises
Wk2 – Ex B1
Write a program called IncrementDecrement that examines pre- and post-increment and decrement.
Declare two integer variables x and y.
Initialise x to 5 and y to 10.
Output the following to the screen in 8 System.out.println statements.
Output x
Output ++x
Output x++
Output x Write down why the output is the way it is.
Output y
Output --y
Output y--
Output y Write down why the output is the way it is.
Console Output:
The value of x is 5
The value of ++x is 6
The value of x++ is 6
The value of x is 7
The value of y is 10
The value of --y is 9
The value of y-- is 9
The value of y is 8