posted 12 years ago
I doubt it. What Satyam probably omitted was some code that is executed for each iteration. A nested loop may help though:
You'll now get a line printed for 10, 20, 30, ..., 90, 100 and finally 105.
Don't forget to add that j < runs or you will have 5 iterations too many. I've turned the 105 into a final int to make sure that i and j have the same upper bound.
Satyam, I honestly would keep your current code with one modification: it should be messageCount % frequency == 0, or you will get lines printed at 11, 21, etc and not at 10, 20, etc. If I do something like this my guard is similar:
After all, messageCount % frequency is 0 if messageCount is 0 (a case where you don't want to have a line printed) or a non-0 multitude of frequency (a case where you do want to have a line printed).