Increment And Decrement In Java Example

Chapter: Operators Last Updated: 15-07-2016 14:02:51 UTC

Program:

            /* ............... START ............... */
                
public class JavaIncrementDecrementOperatorExample {
	public static void main(String[] args) {
		int i = 10;
		int j = 10;
		i++;
		j++;
		
		System.out.println("i = " + i);
		System.out.println("j = " + j);
		int k = i++;
		int l = ++j;	
		System.out.println("k = " + k);
		System.out.println("l = " + l);
	}
}
                /* ............... END ............... */
        

Output

i = 11
j = 11
k = 11
l = 12

Notes:

  • Java increment operator ++ increases its operand's value by one while decrement operator -- decreases its operand's value by one.
  • Increment and Decrement Operators are Unary Operators.
  • Prefix Increment : First Increment Value and then Assign Value.
  • Postfix Increment : Increment Value of Variable After Assigning.

Tags

Increment And Decrement, Java

Similar Programs Chapter Last Updated
Java Left Shift Operator Operators 04-09-2018
Java Addition Operator Operators 18-05-2017
Java Right Shift Operator Operators 13-12-2016
Prefix Operator In Java Example Operators 19-06-2016
Logical Operators In Java Example Operators 17-06-2016
Operator Precedence In Java Examples Operators 17-06-2016
Ternary Operators In Java Example Operators 15-07-2016
Relational Operators In Java Example Operators 11-06-2016
Modulus Operators In Java Example Operators 15-07-2016
Boolean Operator In Java Example Operators 15-07-2016
Bitwise Operator In Java Example Operators 16-06-2017
Assignment Operation In Java Example Operators 06-04-2016
Arithmetic Operation In Java Example Operators 11-06-2016

1