This is a homework assignment and I am stuck and I have researched every book I know that talks about loops.

I am required to print the loop at every 25th loop up to 500, i.e. 1-25th, 26-75th, 100th, 125th, etc.

I guess another way of stating my problem is that I want to sum up the toss results for every 25 loop iterations up to 500. Can someone please explain how I can do this? Right now my code is printing all 500 loops.

package coin; import java.util.Random; public class Coin { public static void main(String[] args) { int heads =0, tails =0, tossResult, total; double tailsPercent, headsPercent; Random coinTossing = new Random(); System.out.println("Number of tosses\t\tNo. of Heads\\ % \t\tNo. of Tails\\ %"); for (int i = 1; i <= 50; i++) { tossResult = coinTossing.nextInt(2); if (tossResult == 0) { heads++; } else { tails++; } total = heads + tails; headsPercent = ((double)(heads)/total)*100; tailsPercent = ((double)(tails)/total)*100; System.out.printf("\t%d\t\t\t\t%d %.1f\t\t%d %.1f", total, heads, headsPercent, tails, tailsPercent); System.out.println(); } } }

If you know a good link that explains this too, please send it my way. Thank you!