public class Increment
1: // Fig. 4.16: Increment.java
2: // Prefix increment and postfix increment operators.
3:
4: public class Increment
5: {
6: public static void main( String args[] )
7: {
8: int c;
9:
10: // demonstrate postfix increment operator
11: c = 5; // assign 5 to c
12: System.out.println( c ); // print 5
13: System.out.println( c++ ); // print 5 then postincrement
14: System.out.println( c ); // print 6
15:
16: System.out.println(); // skip a line
17:
18: // demonstrate prefix increment operator
19: c = 5; // assign 5 to c
20: System.out.println( c ); // print 5
21: System.out.println( ++c ); // preincrement then print 6
22: System.out.println( c ); // print 6
23:
24: } // end main
25:
26: } // end class Increment
27:
28: /**************************************************************************
29: * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
30: * Pearson Education, Inc. All Rights Reserved. *
31: * *
32: * DISCLAIMER: The authors and publisher of this book have used their *
33: * best efforts in preparing the book. These efforts include the *
34: * development, research, and testing of the theories and programs *
35: * to determine their effectiveness. The authors and publisher make *
36: * no warranty of any kind, expressed or implied, with regard to these *
37: * programs or to the documentation contained in these books. The authors *
38: * and publisher shall not be liable in any event for incidental or *
39: * consequential damages in connection with, or arising out of, the *
40: * furnishing, performance, or use of these programs. *
41: *************************************************************************/