Increment and Decrement Examples in Java


Here is the simple program for printing increment and decrement example in Java.

Source Code

import java.io.*;
import java.util.Scanner;
class inc_dnc
{
  public static void main(String args[])
  {
   // ++ --  a=0 a++; a=a+1; a=1;
   /*
     www.tutorjoes.com
   */
   int a=0;
   System.out.println("The Value of A :"+a);
   System.out.println("The Value of A++ :"+a++);
   System.out.println("The Value of A :"+a);
   a=0;
   System.out.println("The Value of ++A :"+(++a));
   a=5;
   System.out.println("The Value of A :"+a);//a=a-1
   System.out.println("The Value of A-- :"+a--);
   System.out.println("The Value of A :"+a);
   System.out.println("The Value of --A :"+(--a));
  }
}
To download raw file Click Here

Output

The Value of A :0
The Value of A++ :0
The Value of A :1
The Value of ++A :1
The Value of A :5
The Value of A-- :5
The Value of A :4
The Value of --A :3


Learn All in Tamil © Designed & Developed By Tutor Joes