Pure Programmer
Blue Matrix


Cluster Map

Project: Incrementing a Variable

Write a program that creates an integer variable named x with the value 1. Print the variable. Then increment the variable by 1 then 2 then 3, printing it after each change. Then decrement the variable three times, by 3 then 2 then 1, printing the value each time.

Output
$ javac -Xlint IncrementingAVariable.java $ java -ea IncrementingAVariable 1 2 4 7 4 2 1

Solution