public class Sample { public static void main(String[] args) { int num1 = 10, num2 = 20; int num3 = 5, num4 = 7; ++num1; System.out.println("now num1: " + num1); System.out.println("now num2: " + (++num2)); // first the num2 gets incremented System.out.println("now num3: " + (num3++)); num4++; System.out.println("now num4: " + (num4)); } } OUTPUT: now num1: 11 now num2: 21 now num3: 5 now num4: 8
demo2
public class Sample { public static void main(String[] args) { int num = 10; System.out.println("now num: " + (num++)); // this is post increment System.out.println("now num: " + num); } } OUTPUT: now num: 10 now num: 11