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; //from   ww  w  .  j  av a2s.  com
    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