import java.util.Random; public class SampleLoopQuestion { public static void main(String[] args) { for (int i = 0; i < 10; i++) { threeHeadsWithForLoop(); System.out.println(); // for a nice output } } public static void threeHeads() { Random rand = new Random(); int count = 0; do { if (rand.nextBoolean()) { System.out.print("H "); count++; } else { System.out.print("T "); count = 0; } } while (count < 3); System.out.println("\nThree heads in a row!"); } public static void threeHeadsWithForLoop() { Random rand = new Random(); for (int count = 0; count < 3;) { // no update since done within the // loop if (rand.nextBoolean()) { System.out.print("H "); count++; } else { System.out.print("T "); count = 0; } } System.out.println("\nThree heads in a row!"); } }