Javatpoint Logo

increment and decrement

By: shravy*** On: Mon Oct 16 17:18:13 IST 2017     Question Reputation0 Answer Reputation0 Quiz Belt Series Points0  0Blank User
examples for post & pre increment and post and pre decrementUp0Down

 
Post increment increments after the statement
Pre increment increments before the statement

Example:
int i = 1 , j = 1;

System.out.println("Post Increment");
while(i++ < 5) {
System.out.println(i);
}

System.out.println("Pre Increment");
while(++j < 5) {
System.out.println(j);
}
Output:
Post Increment
2
3
4
5
//The condition check starts from 1 < 5,2 < 5,3 < 5,4 < 5,5 < 5 -- break
Pre Increment
2
3
4
//The condition check starts from 2 < 5,3 < 5,4 < 5,5 < 5 -- break
Image Created0Down

By: [email protected] On: Sun Oct 29 18:27:13 IST 2017 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No
 
Post increment increments after the statement
Pre increment increments before the statement

Example:
int i = 1 , j = 1;

System.out.println("Post Increment");
while(i++ < 5) {
System.out.println(i);
}

System.out.println("Pre Increment");
while(++j < 5) {
System.out.println(j);
}
Output:
Post Increment
2
3
4
5
//The condition check starts from 1 < 5,2 < 5,3 < 5,4 < 5,5 < 5 -- break
Pre Increment
2
3
4
//The condition check starts from 2 < 5,3 < 5,4 < 5,5 < 5 -- break
Image Created0Down

By: [email protected] On: Sun Oct 29 18:28:00 IST 2017 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No