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

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

Java program to check if user input is an even number

Archived Comments

1. Very good
View Tutorial          By: take at 2010-03-29 07:47:01

2. example is ok, but plz increases the standard of e
View Tutorial          By: venky at 2009-05-19 01:29:04

3. I can't compile the source with Dev-C++ 4.9.9.2, h
View Tutorial          By: ToKha at 2013-11-19 01:32:34

4. It is very useful for me guyzz......thanx.......:-
View Tutorial          By: Rajesh at 2012-09-29 10:11:45

5. Hi,
Nice example....it's a good one to impl

View Tutorial          By: Anish at 2009-07-08 00:21:16

6. one closing bracket ')' is required at while loop
View Tutorial          By: varsha Tambe at 2013-01-07 09:34:37

7. VERY HELPFUL TO ME AND MY FRIENDS.
THANK YO

View Tutorial          By: mansi at 2009-12-23 00:35:43

8. please sent the java code for course plan automati
View Tutorial          By: vijayakumar.r.r at 2009-08-27 01:39:22

9. This should save some time

class pa

View Tutorial          By: vamsi gude at 2012-03-20 18:27:24

10. You can save a file from the content of the input.
View Tutorial          By: anne at 2011-11-22 10:50:10