Comment on Tutorial - Increment and Decrement Operator By aathishankaran



Comment Added by : NewB_of_java

Comment Added at : 2012-02-16 16:52:05

Comment on Tutorial : Increment and Decrement Operator By aathishankaran
Answer for Comment 4 :

" n=n++ ; " is a useless line !! it doesn't do anything. what's actually happening there is, that the value of n was assigned 0, So, when you run the loop the value of n++ gets stored in n (as we had n=n++) which is 0 (as a post increment operator first reads the value then increments 1to it). So the value of n++ is 0 which is being stored by n . *output comes 0 for the first loop and as following by all other loops output is 0 till the end*

In simple way !!

int n=0;
for(int m=0 ; m<5 ; m++){
n=n++ //n++ == 0 at this time so, n becomes 0
}


To avoid this useless thing instead of using
n=n++;
use
n++; //This would add 1 in each loop :)

Thank you . I hope now you don't have any doubt on "n=n++;" ;)


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. if suppose i am having connection pool max size 30
View Tutorial          By: Shrikant at 2012-07-20 12:09:33

2. Hi,

Can anyone suggest a GSM Modem

View Tutorial          By: Archna at 2009-11-06 03:23:14

3. Nice Explanation.....
View Tutorial          By: Vinoth at 2012-06-20 09:37:21

4. Thanks! It worked fine for me.
View Tutorial          By: John Franklin at 2009-04-02 10:37:44

5. very very thankssssssssssssssss
View Tutorial          By: gowtham at 2010-07-31 22:58:36

6. I writing a main class in the eclipse IDE and call
View Tutorial          By: adam lim at 2013-03-11 04:13:51

7. Easy to understand........ thanks man
View Tutorial          By: vikash bhardwaj at 2013-06-25 07:07:54

8. i want to learn j2me basic to ....
View Tutorial          By: gopiraj at 2012-12-21 11:52:01

9. Great! Thanks!
View Tutorial          By: sciarp at 2008-05-11 05:04:17

10. Great examples Eric! Really helped me out a lot, m
View Tutorial          By: Markus at 2008-11-12 05:27:05