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. good but you don't express the programs examples
View Tutorial          By: anchal at 2010-09-29 02:40:02

2. thank you :)
really helped... :)

View Tutorial          By: Tejas at 2011-03-22 14:17:46

3. It would be nice to add the line,


View Tutorial          By: Anonymous at 2009-08-30 07:59:10

4. awesome!!!explanation
View Tutorial          By: karthik at 2013-02-02 08:06:40

5. Good.understand
View Tutorial          By: Selva at 2009-12-29 23:27:29

6. Is so easy work with FacesContext. For me, the get
View Tutorial          By: Fred at 2009-03-11 08:42:59

7. thanks! great tutorial!
View Tutorial          By: Gracia at 2013-01-10 07:58:06

8. class loop8
{
public static voi

View Tutorial          By: ankush singh at 2011-11-04 16:26:36

9. Thank you so much Eric Giguere.
You save me

View Tutorial          By: ijAcK D at 2009-10-18 05:02:48

10. That's really daam !!! simple example :) .........
View Tutorial          By: akshay sharma at 2011-05-03 04:49:15