0
public class increaments {
      public static void main(String args[]){

            int a,b,c,d; 

            a=1; b=2; c=++b; d=a++; c++;        


            System.out.println(""+a);
            System.out.println(""+b);

            System.out.println(""+c);

            System.out.println(""+d);
      }
}

Result of program:

2
3
4
1

Actually I can't understand this program as in this program value of a and b is assigned 1&2 resp. But it show 2&3 resp. I don't know why, as I have not incremented it, but it still increased.

Please tell why and these increments and decrements work.

u32i64
  • 2,384
  • 3
  • 22
  • 36

0 Answers0