title: Using a while loop to go back to start
body: <p>/<em>---------------------------------------
  -----------------Quizzes.java------------
  ----------------------------------------</em>/
     import java.util.Scanner;
      import java.text.NumberFormat;</p>
  
  <p>public class Quizzes
     {
        public static void main(String[] args)
        {</p>
  
  <pre><code>     Scanner scan = new Scanner(System.in);
          NumberFormat per = NumberFormat.getPercentInstance();     
  
  
    //User to input keys for quiz
       System.out.println("How many questions are in the quiz?");
       int numques = scan.nextInt();
       int[] keys = new int[numques];
  
       for (int i=0; i&lt;keys.length; i++)
       {
          System.out.print("Please enter the key for # " + (i+1)+ ": " );
          keys[i] = scan.nextInt();         
       }
  
    //User to input answer
       System.out.println("\nGrading Quizzes");
       System.out.println("--------------------");
  
          int correct=0;
  
       for (int i=0; i&lt;keys.length; i++)
       {
          System.out.println("Please enter the answer for # " + (i+1)+ ":  ");
          int answer= scan.nextInt();
              if (answer== keys [i])
              {
                  System.out.print("Number "+(i+1)+" is correct.\n");
                  correct++;
              }
              else 
              {
                  System.out.print("Number "+(i+1)+" is incorrect.\n");
  
              }
       }
      double cal=(double) correct/numques;
          System.out.println("Total number of correct is "+correct);
       System.out.println("The percent correct is " +per.format(cal));
  
          System.out.println("Would you like to grade another quiz? (y/n)");
          String user_input=scan.next();
  
          while(user_input.equals("y"))
          {   correct=0;
       for (int i=0; i&lt;keys.length; i++)
       {
          System.out.println("Please enter the answer for # " + (i+1)+ ":  ");
          int answer= scan.nextInt();
              if (answer== keys [i])
              {
                  System.out.print("Number "+(i+1)+" is correct.\n");
                  correct++;
              }
              else {
              System.out.print("Number "+(i+1)+" is incorrect.\n");   }
  
              } 
             cal=(double) correct/numques;
             System.out.println("Total number of correct is "+correct);
          System.out.println("The percent correct is " +per.format(cal));
        }
             System.out.println("Goodbye!");
  
   }
  </code></pre>
  
  <p>}</p>
  
  <p>How would I make the program go back to where the user would have to enter the answer using the while loop? No matter what I tried, right when it prints out, "Would you like to grade another quiz, and if the user type y, it would just end. Can anyone point out what I'm doing wrong</p>
  
  <p>Edit 1: Well I got it to re-run again after the while loop but it keep asking me to input the answer for the question over and over and over again, it doesn't break out of the loop,it doesn't go back to the part where it asked if I wanted to grade another. This is the output</p>
  
  <p>How many questions are in the quiz?
  2
  Please enter the key for # 1: 1
  Please enter the key for # 2: 2</p>
  
  <h2>Grading Quizzes</h2>
  
  <p>Please enter the answer for # 1:<br>
  1
  Number 1 is correct.
  Please enter the answer for # 2:<br>
  3
  Number 2 is incorrect.
  Total number of correct is 1
  The percent correct is 50%
  Would you like to grade another quiz? (y/n)
  y
  Please enter the answer for # 1:<br>
  1
  Number 1 is correct.
  Please enter the answer for # 2:<br>
  2
  Number 2 is correct.
  Total number of correct is 2
  The percent correct is 100%
  Please enter the answer for # 1:<br>
  1
  Number 1 is correct.
  Please enter the answer for # 2:<br>
  2
  Number 2 is correct.
  Total number of correct is 2
  The percent correct is 100%
  Please enter the answer for # 1:  </p>