Java - Using post-fix and pre-fix decrement operators

Description

Using post-fix and pre-fix decrement operators

Demo

public class Main {
  public static void main(String[] args) {
    int i = 15; // w ww  .j a va2s. co  m
    int j = 16; 
    i--; 
    System.out.println(i);
    --i; 
    System.out.println(i);
    i = 10; 
    i = i--;       // Assigns 10 to i
    System.out.println(i);
    i = 10; 
    j = i-- + 10;  // Assigns 20 to j and 9 to i
    System.out.println(j);
    i = 10; 
    j = --i + 10;  // Assigns 19 to j and 9 to i 

    System.out.println(j);
  }
}

Result

Related Topic