preincrement or pre-decrement, post-increment or post-decrement : Unary Operators « Operators « SCJP






public class MainClass{
    public static void main(String[] argv){

      int i = 0;
      int y = 0;
      y = i++;
      System.out.println(i);
      System.out.println(y);
    }
}

1
0

public class MainClass{
    public static void main(String[] argv){

      int i = 0;
      int y = 0;
      y = ++i;
      System.out.println(i);
      System.out.println(y);
    }
}
1
1

public class MainClass{
    public static void main(String[] argv){

      int i = 0;
      int y = 0;
      y = i--;
      System.out.println(i);
      System.out.println(y);
    }
}
-1
0


public class MainClass{
    public static void main(String[] argv){

      int i = 0;
      int y = 0;
      y = --i;
      System.out.println(i);
      System.out.println(y);
    }
}
-1
-1








2.2.Unary Operators
2.2.1.Unary operators take only a single operand.
2.2.2.The unary operators are used to increment, decrement, or change the sign of a value.
2.2.3.Increment and Decrement
2.2.4.+ and - operators are applied to a value of byte, char, and short types, the value is converted to an int.
2.2.5.The ++ operators may appear before the value (prefix) or after the value (postfix).
2.2.6.preincrement or pre-decrement, post-increment or post-decrement
2.2.7.mixing the increment and decrement operators with other operators
2.2.8.increment or decrement operators on a final variable.