Two Laptop Bag*
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
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: 11175
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Providing feedback when processing a large for loop
 
Similar Threads
Converting Number to Word
Dice probability program, using nested loops.
Head first Beersong
converting a double value
Printing arrays of ints