title: Need to add a heads/tails streak counter for my code
body: <p>This code flips an imaginary coin a thousand times and tallies the total number of heads or tails.</p>
  <pre><code>import java.util.*;
  public class CoinFlipper {
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
      
          int headsCount = 0;
          int tailsCount = 0;
          int numFlips = 1000;
          for (int i = 1; i &lt;= numFlips; i++) {
              
              Random rand = new Random();
              System.out.println(&quot;Flip &quot; + i + &quot;: &quot;);
              boolean flip = rand.nextBoolean();
              if (flip) {
                  
                  System.out.println(&quot;Heads&quot;);
                  headsCount++;
              }else { 
                  System.out.println(&quot;Tails&quot;);
                  tailsCount++;
              }
              
          }
          
          System.out.println();
          System.out.println(&quot;Number of Heads: &quot; + headsCount);
          System.out.println(&quot;Number of Tails: &quot; + tailsCount);
          System.out.println();
          System.out.println(&quot;Longest Streak of Heads: &quot;);
          System.out.println(&quot;Longest Streak of Tails: &quot;);
      }
  
  }
  </code></pre>
  <p>However, I also need to figure out the longest streak of heads or tails results (i.e. &quot;Heads, Heads, tails, heads, heads, heads&quot; would have a longest streak of 3).</p>
  <p>How would I go about keeping track of the longest streak?</p>