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. Hi,
can anyone show or send me a sample pro

View Tutorial          By: jsn10 at 2011-09-14 05:41:03

2. Thanks, Just what i was looking for.
View Tutorial          By: Baapu at 2009-10-21 15:21:43

3. Thanks,It's perfect solution,I solved my probleam
View Tutorial          By: Suryaprakash Raghuwanshi at 2009-07-04 19:06:24

4. In listing 6.2 I don't see the variable name itsAg
View Tutorial          By: JC at 2013-04-16 01:49:52

5. thanks for all samples..
View Tutorial          By: 珠洲市 at 2013-03-01 09:47:46

6. Hi,

i need a program to send sms wh

View Tutorial          By: Sindhuja at 2013-05-29 07:07:15

7. Another solution to those, who feel that the probl
View Tutorial          By: Zoltán P. Ackermann at 2010-12-09 01:58:51

8. Only first row is exported, help to export all the
View Tutorial          By: Achyut at 2014-12-18 04:26:26

9. Thanks very much.
View Tutorial          By: Haritha at 2011-05-26 07:56:06

10. thank u.....
View Tutorial          By: DiptaRanjan at 2013-02-02 14:56:45