/** * Name: Erica Eddy * Course: CSCI 241 - Computer Science I * Section: 001 or 002 * Assignment: 1 * * This class demonstrates the difference between: * pre-increment (++ or -- appears before the variable name), and * post-increment (++ or -- appears after the variable name). */ public class PrePostIncr { public static void main (String [] args) { int i = 6; // First, print the original value of i System.out.println ("New Run: i = " + i); // Use PostIncrement to print old value of i, then increment System.out.println ("i++ = " + (i++)); // Print current value of i System.out.println ("i = " + i); // Use PreIncrement to first increment i, then print its new value System.out.println ("++i = " + (++i)); // Print current value of i System.out.println ("i = " + i); i = i++; System.out.println ("After i = i++; i = " + i); i = ++i; System.out.println ("After i = ++i; i = " + i); int a = 1; int b = ++a; System.out.println("a= " + a); System.out.println("b= " + b); } }