public class PrePostDemo
{
public static void main(String[] args)
{
int a = 4;
int b = 4;
System.out.println(a);
a++;
System.out.println(a);
a++;
System.out.println(a++);
System.out.println(b);
++b;
System.out.println(b);
++b;
System.out.println(++b);
}
} |
The increment/decrement operators can be applied before (prefix) or after (postfix) the operand. The code a++; and ++b; will both end in result being incremented by one. The only difference is that the prefix version (++b) evaluates to the incremented value, whereas the postfix version (a++) evaluates to the original value.
Tags: Java, operations, unary
October 4th, 2014 at 10:08 pm
Hello,
Not sure how I came here, but happy to read your website. Keep posting!