Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Annie Russell   on Apr 27 In Java Category.

  
Question Answered By: Lela Lynch   on Apr 27

If I understood your problem correctly, in your class  the execution of for loop
is same in both the cases, i.e, first i=0, then it increments i to 1 since u
gave i++ and checks for i<2 and continue like. The difference is in 'a', value
Ist loop, when i=0, since it is a++ in ur print statement, a=1 in output, after
that it is incremented to 2 . so when i=1, a=2 in output, after which is
incremented to 3.
2nd loop, when i=0, since it is ++a in ur print statement, it is incremented to
2, so u get output as 2. When i=1, it is again incremented to 3 and output u get
is 3.

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on post vs pre increment implementation Or get search suggestion and latest updates.


Tagged: