aspose file tools
The moose likes Beginning Java and the fly likes How do we get this output ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "How do we get this output ?" Watch "How do we get this output ?" New topic
Author

How do we get this output ?

Mohnish Khiani
Ranch Hand

Joined: May 17, 2010
Posts: 65


Output : 0
How do we get output as 0?
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 490

j++ means that the value of j will increase by 1 after the statement is processed.

So when you do:

You are really doing:


So j gets assigned 0, THEN the value on the right hand side turns into 1, but at that point it doesnt matter because the loop executes again and the right hand side is lost.

try this:


"If the facts don't fit the theory, get new facts" --Albert Einstein
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12953
    
    3

See the following page in our FAQ: Post Increment Operator And Assignment


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32833
    
    4
Please search this forum for "postincrement" and "preincrement" because lots of people get confused about this very same question and there are frequent posts about it.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 8566

Just for fun, change
j=++j;
to
j+=1;


[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

or just to j++;


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How do we get this output ?
 
Similar Threads
array question
Doubt on Post Increment operator.
three for Loops?
can someone explain this?
How to create this String array