• We Code
  • We Design
  • We Develope
  • We Write
  • We Share

menu

Wednesday, August 15, 2012

Increment And Decrement Operator in Java

There are two arithmetic  operator ++ and -- . Both are unary operators and operate only on integers . The ++ is called increment operator and -- is called decrement operator 


  1. The ++ operator  in prefix increments operand first  and the uses operand  next
  2. The ++ operator in suffix/postfix uses operand first and then increments operand 
  3. The -- operator  in prefix decrements operand first and  the uses the operand next
  4. The -- operator in suffix/postfix uses operand first and then decrements operand

Eample of the Increment And Decrement  Operator :


//PrefixPostfixTest.java


public class  PrefixPostfixTest
{
  public static void main (String args[]) throws Exception
{
int i=45,j=35;
System.out.println("i is "+i);
System.out.println("++i is "+(++i));
System.out.println("j is "+j);

 
System.out.println("j++ is "+(j++));
System.out.println("--i is "+(--i));
System.out.println("j is "+j);
System.out.println("j-- is "+(j--));
}
}


commands for compiling and running the program 

For compilation ------ javac prefixpostfixtext.java
For Execution--------- java   prefixpostfixtext

1 comments:

...