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 morning!
I need help about how to conf

View Tutorial          By: alpha at 2009-06-14 03:20:41

2. Hi,

I tried use this code:
<

View Tutorial          By: Yanosh at 2009-07-16 05:19:38

3. Good one.........!!!
View Tutorial          By: Shailesh Nakade at 2012-07-11 09:48:33

4. vinod kumar for j2me app development we need one I
View Tutorial          By: saurabh dixit at 2013-04-18 09:59:23

5. program is very long
View Tutorial          By: ajit kumar at 2012-04-21 03:57:13

6. Good
View Tutorial          By: sirisha at 2009-09-08 23:04:22

7. Thankyou it is Working Fine .....
View Tutorial          By: PDCOE at 2009-02-11 23:02:29

8. i think this ist perfectly fine :) if you don't kn
View Tutorial          By: julian at 2011-03-07 05:54:08

9. but need in the case of radio buttons
View Tutorial          By: vishnu at 2011-07-21 11:39:26

10. Hi, it looks great!
I'm just starting with

View Tutorial          By: Bertrand at 2013-04-28 19:20:42