Increament operator error - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Increament operator error

himanshu124himanshu124 Posts: 2Member
i started learning JAVA a few days back.
i thought of writing my first program on arithmetic operators.
but i m getting compilation error with the "++" operator.
below is my code.
[code]public class IntArithmeticOperations {
public static void main(String args[]){
System.out.println("Arithmetic Operations Sample");

int i=10;

int increamentResult=++i;//This is ok
int increamentResult1=++(i);//This is also ok
int increamentResult2=doit(++i); //This is also ok
int increamentResult3=++(++i); //This gives a compilation
int increamentResult4=++(i=i++); //This gives a compilation error
int increamentResult5=++(i+1); //This gives a compilation error

System.out.println("IncreamentResult is"+increamentResult);
System.out.println("IncreamentResult1 is"+increamentResult1);
System.out.println("IncreamentResult2 is"+increamentResult2);
System.out.println("IncreamentResult3 is"+increamentResult3);
System.out.println("IncreamentResult4 is"+increamentResult4);
System.out.println("IncreamentResult5 is"+increamentResult5);
public static int doit(int i){
return i;

Please help me understand how the "++" operator works.
Sign In or Register to comment.