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!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.