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
//PrefixPostfixTest.java
- The ++ operator in prefix increments operand first and the uses operand next
- The ++ operator in suffix/postfix uses operand first and then increments operand
- The -- operator in prefix decrements operand first and the uses the operand next
- 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--));}}
For compilation ------ javac prefixpostfixtext.java
For Execution--------- java prefixpostfixtext
nice bolg...this is very easy way to learn java...
ReplyDelete