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++; //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. Can anybody send full code for sending and receivi
View Tutorial          By: Jayapal at 2010-08-12 11:41:38

2. Hello,
could you send me the complete code

View Tutorial          By: Sanjay at 2013-04-19 07:28:12

3. Hi Divya, Obviously some other application is usin
View Tutorial          By: Ramlak at 2008-05-01 22:16:12

4. The code gives the following exception :-

View Tutorial          By: Lourdu Felix at 2009-01-26 03:37:53

5. sir needed help i am compiler dev c++ which shown
View Tutorial          By: shahab at 2010-05-05 13:17:53

6. Hi, I cant open the file after I click Write SD. I
View Tutorial          By: hassan at 2014-12-17 07:44:16

7. date span progarm sorce code in jsp by using strin
View Tutorial          By: prudhvi at 2013-01-27 13:55:09

8. Great tutorial about ArrayList .It's a very great
View Tutorial          By: umesh sharma at 2009-05-14 20:40:39

9. Thanks friend this code will really help me

View Tutorial          By: Anonymous at 2009-05-04 20:16:58

10. how to download suport to my phone
send me

View Tutorial          By: dede.mouljadie at 2012-04-28 09:39:21