Incrementing and Decrementing operators in Java Programming

Incrementing and Decrementing operators in Java Programming

Previous Home Next

 

Incrementing and Decrementing operators in Java Programming are (++ )and (- - )operators.
 Java provides special operators for Incrementing and decrementing as they are such common operations .

In computer programming it is quite common to want to increase or decrease the value of an integer type by 1. 
Because of this Java provides the increment and decrement operators that add 1 to a variable and subtract 1
from a variable, respectively. The increment operator is denoted by two plus signs (++), and the decrement operator is denoted by two minus signs (--).
 variable++;
++variable;
variable--;
--variable;


 
class Demmo {

public static void main (String args[]) {

int x = 1;

int y = 2;

int p;

int q;

p = ++x;

q = y++;

p++;

System.out.println("x = "+ x);

System.out.println("y= " + y);

System.out.println("p = " + p);

System.out.println("q = " + q);

}

}


Previous Home Next