Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

how do i record the number of times all runs of heads occur. ex. Length Number o

ID: 638030 • Letter: H

Question

how do i record the number of times all runs of heads occur.

ex.

Length Number of runs of heads
1 --------------------3
2 --------------------2
3 --------------------0
4 --------------------1

public static void main(String[] args)
{
       int [] coinToss = new int[TOSSES];
       int longestRun = 0;
       int run = 0;


       for(int i = 0; i < coinToss.length; i++)
           coinToss[i] = toss();

       record(coinToss);

       for(int i = 0; i < coinToss.length; i++)
       {
           if(coinToss[i] == 0)
               {
               run++;
               if(run > longestRun)
                   longestRun = run;

               }
           else
               {
               run = 0;
               }
               System.out.print(coinToss[i]+" ");

       }

   }

   public static int toss()
   {
       Random rnd = new Random();

       int coin = rnd.nextInt(2);

       return coin;
   }
   public static void record(int[] values)
   {
       for(int i = 0; i < values.length; i++)
       {
          
       }
   }
   public static final int TOSSES = 100;
}

Explanation / Answer

Increase Points..