Showing posts with label Increment and Decrement Operators. Show all posts
Showing posts with label Increment and Decrement Operators. Show all posts

Java - Increment and Decrement Operators / Chapter -1 /Operator & Assignments





javabychetan.blogspot.com


Increment Operator


In java, there are two types of increments operators



  • Pre-Increments          b = ++a;

  • Post-Increments        b =  a++;



Decrement Operator



In java, there are two types of decrements operators



  • Pre-Decrements          b  = --a;

  • Post-Derement           b  =  a--;



Lets understand more by following examples:-

Java - Increment and Decrement Operators / Chapter -1 /Operator & Assignments

javabychetan.blogspot.com

Increment Operator

In java, there are two types of increments operators

  • Pre-Increments          b = ++a;
  • Post-Increments        b =  a++;
Decrement Operator

In java, there are two types of decrements operators


  • Pre-Decrements          b  = --a;
  • Post-Derement           b  =  a--;
Lets understand more by following examples:-

int a=10;
int b;
Expression               initial value of a              value of b           after the completing expression final value of a
b = ++a                            10                               11                                11
b = a++                            10                               10                                11
b = -- a                            10                                9                                  9
b = a--                             10                                10                                9

Rule 1.
We can apply increment & decrement operators only for variables but not for constant value.
If we are trying to apply for constant value then we will get Compile Time Error.
example 1:-

Flipkart End Of Season Sale






© Copyright 2017 Javabychetan.blogspot.com