title: Outside loop to run my program 1000 times and keep a tally - Java
body: <p>I used to have some basic java skills but it has been a couple of years since I used them. My program does everything I want once, but I need it to run the program 1000 times and keep a total of the <code>rtCorrect</code> and <code>rtIncorrect</code>. Those 2 totals are actually the only things I will need in the end (i.e. I will only need that last commented out statement). I am not sure if I should just be adding an outside loop in my main method or if I should have a seperate method. I am not worried about it being pretty so I would rather just do it all in the main method with a simple loop.</p>
  
  <pre><code>import java.util.Random;
  
  public class Thesis {
  
          public static void main (String [] args){
  
          int correct = 0;
          int incorrect = 0;
          int rtCorrect = 0;
          int rtIncorrect = 0;
  
  
              while(correct&lt;20 &amp;&amp; incorrect&lt;20){
                      Random rand = new Random();
                      int pickedNumber = rand.nextInt(100);
                      if (pickedNumber&lt;52){
                          correct++;
                      }
                      else if (pickedNumber&gt;51){
                          incorrect++;
                      }
                      if (correct == 20){
                          rtCorrect = rtCorrect + correct + incorrect;
                      }
                      else if (incorrect == 20){
                          rtIncorrect = rtIncorrect + incorrect + correct;
                      }
                  }
  
          }
          System.out.printf("Correct: %d Incorrect: %d", correct, incorrect);
          System.out.printf ("\nCorrect Response Time: %d\nIncorrect Response Time: %d", rtCorrect, rtIncorrect);
          //System.out.printf ("\nTotal Correct RT's: %d \nTotal Incorrect RT's: %d", totalRTCorrect, totalRTIncorrect);
  
      }
  
  }
  </code></pre>
  
  <p>Here is what I have tried:</p>
  
  <pre><code>import java.util.Random;
  
  public class Thesis {
  
          public static void main (String [] args){
  
          int correct = 0;
          int incorrect = 0;
          int rtCorrect = 0;
          int rtIncorrect = 0;
  
  
          for (int j = 0; j &lt; 1000;j++){
              int totalRTIncorrect = 0;
              int totalRTCorrect = 0;
  
              while(correct&lt;20 &amp;&amp; incorrect&lt;20){
                      Random rand = new Random();
                      int pickedNumber = rand.nextInt(100);
                      if (pickedNumber&lt;52){
                          correct++;
                      }
                      else if (pickedNumber&gt;52){
                          incorrect++;
                      }
                      if (correct == 20){
                          rtCorrect = rtCorrect + correct + incorrect;
                      }
                      else if (incorrect == 20){
                          rtIncorrect = rtIncorrect + incorrect + correct;
                      }
                  }
  
                  totalRTIncorrect = totalRTIncorrect + rtIncorrect;
                  totalRTCorrect = totalRTCorrect + rtCorrect;
                  System.out.printf ("\nTotal Correct RT's: %d \nTotal Incorrect RT's: %d", totalRTCorrect, totalRTIncorrect);
          }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>import java.util.Random;
  
  public class Thesis {
  
          public static void main (String [] args){
  
          int correct = 0;
          int incorrect = 0;
          int rtCorrect = 0;
          int rtIncorrect = 0;
          int totalRTIncorrect = 0;
          int totalRTCorrect = 0;
  
          for (int j = 0; j &lt; 1000;j++){
  
              while(correct&lt;20 &amp;&amp; incorrect&lt;20){
                      Random rand = new Random();
                      int pickedNumber = rand.nextInt(100);
                      if (pickedNumber&lt;52){
                          correct++;
                      }
                      else if (pickedNumber&gt;52){
                          incorrect++;
                      }
                      if (correct == 20){
                          rtCorrect = rtCorrect + correct + incorrect;
                      }
                      else if (incorrect == 20){
                          rtIncorrect = rtIncorrect + incorrect + correct;
                      }
                  }
  
                  totalRTIncorrect = totalRTIncorrect + rtIncorrect;
                  totalRTCorrect = totalRTCorrect + rtCorrect;
          }
          System.out.printf ("\nTotal Correct RT's: %d \nTotal Incorrect RT's: %d", totalRTCorrect, totalRTIncorrect);
          //System.out.printf("Correct: %d Incorrect: %d", correct, incorrect);
          //System.out.printf ("\nCorrect Response Time: %d\nIncorrect Response Time: %d", rtCorrect, rtIncorrect);
  
  
      }
  
  }
  </code></pre>
  
  <p>Neither one of these is giving me what I need. The first one just prints out one iteration of the program 1000 times and the second one gives me one of the RT's as 34000 or whatever RT it came to on one iteration x 1000 and the other RT as 0 </p>