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



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. Don't forget the native type char, which is a 16 b
View Tutorial          By: Ron Stern at 2011-09-18 17:24:12

2. dude its forces closes everytime what to do .....h
View Tutorial          By: raam at 2013-01-10 13:05:57

3. very cool you said it! many thanks it's really coo
View Tutorial          By: ArAsh at 2008-12-11 06:41:13

4. Travis could you share steps to configure correctl
View Tutorial          By: Shailesh S. at 2015-09-09 09:36:20

5. can i use comma operator in simbolic constant in c
View Tutorial          By: Madheswaran at 2011-12-05 18:44:22

6. Please i want to ask if this solution is really wo
View Tutorial          By: Enas Sabry at 2008-02-20 04:16:39

7. I am getting the error below.

Tue J

View Tutorial          By: ganesh at 2008-07-01 05:35:31

8. thanks for this pertinent remark.
View Tutorial          By: mohammed at 2009-02-21 05:43:11

9. Hi,
I have problem of calling javascript fu

View Tutorial          By: Shakti Prasad Priyakumar at 2008-06-06 06:11:52

10. ya its correct but tell me where is main method???
View Tutorial          By: kashiNATH MOKASHI at 2011-08-20 05:33:19