title: having trouble understanding count and average
body: <p>Description: I have to create a program that simulates a man standing on a seven foot bridge, while the man stands in the middle(3.5 ft). I have to use a random number simulator and puts on either 0 or 1. 1 representing one step forward, while 0 represents one step backwards. when the man steps off the bridge (less than 0 or greater than 7) then it restarts. I am supposed to run this 1000 times(not shown in output). Then, I have to calculate the avg number of steps he takes before walking off. Also, I have to calculate the greatest number of steps he took in the 1000 runs. So far, I am having trouble creating a count, making an average, and how to calculate the greatest number of steps. Can anyone help me understand a better way to look at my coding for doing all of this. Any help would be appreciated.</p>
  <pre><code>import java.util.*;
  public class Prog214a
  {
     public static void main(String[] args)
     {
         int greatesNumOfSteps;
         double bridge,sum,avg;
         int beginning = 1;
         double midway = 3.5;
  
         System.out.println(&quot;Run     Average     Greatest Number of Steps&quot;);
  
         for(beginning = 1; beginning &lt;= 1000; beginning++)
         {
             Random randomNum = new Random();
             int step = randomNum.nextInt(2);
             if(step == 1)
             {
                 midway = midway + 1;
                 sum = midway;
                
             }
             else
             {
                 midway = midway - 1;
                 sum = midway;
             }
             if(midway &lt; 0.5 || midway &gt; 6.5)
             {
                System.out.println(&quot;#&quot; + beginning + &quot;     ...&quot;);
                midway = 3.5;
             }
         }
     }
  }
  
  /**My Output:
  
  Run     Average     Greatest Number of Steps
  #10     ...
  #34     ...
  #46     ...
  #58     ...
  #122     ...
  #132     ...
  #148     ...
  #160     ...
  #188     ...
  #218     ...
  #228     ...
  #266     ...
  #312     ...
  #322     ...
  #338     ...
  #344     ...
  #376     ...
  #394     ...
  #398     ...
  #408     ...
  #418     ...
  #426     ...
  #438     ...
  #444     ...
  #452     ...
  #470     ...
  #480     ...
  #526     ...
  #542     ...
  #546     ...
  #562     ...
  #576     ...
  #584     ...
  #616     ...
  #662     ...
  #668     ...
  #704     ...
  #726     ...
  #732     ...
  #740     ...
  #750     ...
  #792     ...
  #798     ...
  #804     ...
  #814     ...
  #818     ...
  #830     ...
  #840     ...
  #844     ...
  #850     ...
  #864     ...
  #874     ...
  #884     ...
  #900     ...
  #914     ...
  #918     ...
  #928     ...
  #968     ...
  #978     ...
  */
  </code></pre>
  <p>This is what is supposed to look like:</p>
  <p>Runs        Average    Greatest Number of Steps</p>
  <h1>1           xx.xx          xx</h1>