Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array output continuous in output window and won't terminate - Any help!!

 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Another simple question I think! Why is the output from this main class not terminating in the output window. The main method is calling an array of 10,000 integers from four seperate text files of telephone numbers. Each file is 10,000 integers long.

When I run this main class it outputs the correct answer but simply does not terminate, and continually repeats the same answer.

Code is as follows:



Any help appreciated!!
 
Stephen Foy
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because the givenNumber is always not equal to 0?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've set givenNumber to 83746, and then said, "while givenNumber is not zero," keep going, and going, and going...

As long as givenNumber has a non-zero value, the loop will keep repeating. So within your loop, you should be setting givenNumber to the next value -- or to zero if you want to stop.
 
Stephen Foy
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want it to only run for one cycle then you do not need the while loop.

Or if you want it to run till its down to 0. Trying using a counter variable or something.


[ November 12, 2005: Message edited by: ste fing ]
 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thank you both for your answers. It was such an obvious mistake, I feel a bit daft now. Anyway, it is now working perfectly so thank you so much for all your help.

Have a great weekend!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic