28 lines
736 B
Java
28 lines
736 B
Java
// operators/AutoInc.java
|
|
// (c)2016 MindView LLC: see Copyright.txt
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
|
// Demonstrates the ++ and -- operators
|
|
|
|
public class AutoInc {
|
|
public static void main(String[] args) {
|
|
int i = 1;
|
|
System.out.println("i : " + i);
|
|
System.out.println("++i : " + ++i); // Pre-increment
|
|
System.out.println("i++ : " + i++); // Post-increment
|
|
System.out.println("i : " + i);
|
|
System.out.println("--i : " + --i); // Pre-decrement
|
|
System.out.println("i-- : " + i--); // Post-decrement
|
|
System.out.println("i : " + i);
|
|
}
|
|
}
|
|
/* Output:
|
|
i : 1
|
|
++i : 2
|
|
i++ : 2
|
|
i : 3
|
|
--i : 2
|
|
i-- : 2
|
|
i : 1
|
|
*/
|