DECREMENT OPERATOR
Decrement Operator:
- We will used decrement operator when we want to decrement the value by one.
- There are two types of decrement operators we have.
- Decrement the value by one.
- Update the decremented value in the same variable.
- Any operation is going on we will used the decremented value.
- class Predecrement
- {
- public static void main(String [] args)
- {
- int c= 23;
- int b= --c;
- int a= --b;
- System.out.println(a);
- System.out.println(b);
- System.out.println(c);
- }
- }
Rules:
- Decrement the value by one.
- Update the decremented value in the same variable.
- Any operation is going on we will used the current value but not the decremented value.
- class Postpredecrement
- {
- public static void main(String [] args)
- {
- int c= 23;
- int b= c--;
- int a= --b;
- System.out.println(a);
- System.out.println(b);
- System.out.println(c);
- }
- }
Output:
22
22
22
22
22
0 Comments