Working of pre-fix increment in Java -


what control flow of post-increment operator?

public class postincrement {     public static void main(string[] args)     {          int = 0;         for(int i=0;i< 2 ;i++)         {             =a++;              }          for(int i=0 ;i< 1;i++)         {             a++;         }          system.out.println("result2 :"+" "+a);             }  } 

the results 0 , 1

why so?

the postfix operator ++ executes after statement completes.

the first time print value of a prints 0 because nothing has changed. next, enter loop executes once, incrementing value of a. doesn't matter postincrement because there no other instructions in statement. value of a 1.

you print out 1.

as aside, code doesn't work because inner variable i hiding outer variable , compiler error redeclaring i. assumed mean different variable here such j.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -