I was working on this codeHS AP CompSci problem (4.3.6)
Basically I have to simulate flipping a coin 100 times, printing out the result (heads or tails) but in the end I need to print out the longest streak of heads.
public class LongestStreak extends ConsoleProgram{ public static final int FLIPS = 100; boolean tailsChosen = true; int count_tails=0; int count_heads=0; int streak = 1; public void run() { for (int i= 1; i<=100; i++) { tailsChosen= Randomizer.nextBoolean(); if (tailsChosen) { System.out.println("Tails"); count_tails++; } else { System.out.println("Heads"); count_heads++; } } System.out.println("Longest streak of heads: "+ streak ); }}
This is my coding so far. I have worked so that I can randomly printout 100 heads and tails but just cannot find a way to find the longest streak of heads..
Thank you