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. its easy to understand your example in overloading
View Tutorial          By: rovie at 2011-09-07 02:41:12

2. can you send me comm.jar required for this project
View Tutorial          By: gayatri at 2013-03-19 09:53:35

3. how come its able to copy from copyFrom to CopyTo.
View Tutorial          By: sameera at 2015-09-12 13:56:29

4. Please send me working code and setup,,My mail id
View Tutorial          By: Karthik at 2012-03-30 19:56:35

5. one of the best example for trim()....
View Tutorial          By: sharad at 2013-01-29 13:43:58

6. these is the error when i run these program

View Tutorial          By: chintan rajpara at 2015-01-05 06:46:25

7. sir i need some simple example of jdbc i cannot un
View Tutorial          By: sumit at 2011-11-26 18:02:14

8. Good start for me. At least I now know what i am s
View Tutorial          By: eoaddai at 2011-12-23 20:53:35

9. Introduction is very clear I get the answer what I
View Tutorial          By: sathya at 2013-02-05 15:57:30

10. Including the required mail properties should solv
View Tutorial          By: Rajesh Vaddi at 2011-12-13 23:55:15