// This program demonstrates shortcut arithmetic expressions
// and the difference between n++ and ++n
// Look at the value of k to see the difference

public class Arith {

    public static void main (String [] args) {
	int n = 1;

	n += 2;
	System.out.println("n = " + n);
	n /= 3;
	System.out.println("n = " + n);

	int k = n++;
	System.out.println("n = " + n + " k = " + k);

	k = ++n;
	System.out.println("n = " + n + " k = " + k);
    }
}

This is an example from CSci 1211 course.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.