wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Could someone please explain what is happening is this problem? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Could someone please explain what is happening is this problem?" Watch "Could someone please explain what is happening is this problem?" New topic
Author

Could someone please explain what is happening is this problem?

raul vargas
Greenhorn

Joined: Mar 15, 2012
Posts: 14

I'm trying to explain why over 20 lines of output gets printed to the console from this code but I really have no idea how

I'd really appreciate if someone could tell what is happening and why there are so many lines of output

The code:

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Output count1 and count2 and you should see what's happening.


[My Blog]
All roads lead to JavaRanch
raul vargas
Greenhorn

Joined: Mar 15, 2012
Posts: 14
What do you mean? just delete count1 and count2? but I then get error messages
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

"Output" does not mean "delete". It means to print out the values.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
raul vargas
Greenhorn

Joined: Mar 15, 2012
Posts: 14

I've outputed count1 like this:

Sytem.out.println(count1)

and all 5 digits show up in the console but each number displays nearly as many times as the original i.e. System.out.println("How many times do we need to trace?");
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Let's try another tactic. Change your output line to:
What can you gather about the results?
raul vargas
Greenhorn

Joined: Mar 15, 2012
Posts: 14

The console now displays from count1 which is 5

and counts up to 20 on each number from count2

Ankit Dan
Ranch Hand

Joined: Aug 31, 2012
Posts: 47

At first,
count1 loop from 1 to 5
inside it count2 loop from 1 to 20
System.out.println("How many times do we need to trace?");
count2 loop ends
count1 loop ends


so for every count1 loop, there are 20 count2 loop.thats it!
Hope it helps!

Ankit
raul vargas
Greenhorn

Joined: Mar 15, 2012
Posts: 14

it did! Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Could someone please explain what is happening is this problem?
 
Similar Threads
thread-deadlock
Problems searching through a list
varstatus in nested foreach
Ternary Operator behavior in JAVA
finding token data type (StringTokenizer)