aspose file tools
The moose likes Beginning Java and the fly likes Providing feedback when processing a large for loop Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Providing feedback when processing a large for loop" Watch "Providing feedback when processing a large for loop" New topic
Author

Providing feedback when processing a large for loop

Mark Waes
Greenhorn

Joined: Aug 06, 2008
Posts: 21
Hi,

This should be easy, but for the life of me I can't figure it out...

I'm looking to provide user feeback when processing a large for-loop, and at each 10% milestone, print the message '10% Complete', '20% Complete' etc..

my code is below, but it suffers from a problem when the countTarget instance variable is an odd number (prime numbers being a specific example) in that not all of the 10% milestones are printed.

Regardless of the number of interations required by the for-loop, I would like to print feedback 10 times.



Any help gratefully received...
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9948
    
    6

the problem is you're using floats here, and floating point arithmetic is never precise. What i'd probably do is something like



You may not get your output at EXACTLY 10%, but pretty dang close.


Never ascribe to malice that which can be adequately explained by stupidity.
 
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: Providing feedback when processing a large for loop
 
Similar Threads
Head first Beersong
Printing arrays of ints
converting a double value
Converting Number to Word
Dice probability program, using nested loops.