title: Why is this Java code not working calculate average max and min?
body: <p>I am supposed to build a program that gets the grades in a class and calculates min and max and average then ask if you want to continue. This is the code I used but it's still not working. Can you see where the mistake is?</p>
  
  <pre><code>public class calculateAvgMAxMin
  {
      public static void main(String[] args)
      {
          Scanner input = new Scanner(System.in); // declares scanner input
          LinkedList&lt;Integer&gt; list = new LinkedList&lt;Integer&gt;(); // declare new LinkedList of variables which are the grades
  
          int answer = 1; // declare variable answer =1 
          do { // start of do loop 
  
              System.out.print("Please enter the name of the course:"); // gives a prompt to enter the name of the course
  
              // goes to the next line
  
              String course=input.nextLine(); // declare course as string and sets the value as the input
  
              System.out.println("Please enter the scores for " + course + " on a single line and type a -1 at the end"); //prompts user to enter scores for class in one line and -1 to stop
  
              int max=-100; // declare max as integer = -100
              int min=500;//declare min as integer = 500
  
              int sum=0;// declare sum as intgetr = 0
              int grade;     // declare grade as integer  
  
              grade=input.nextInt(); // set grade as next user iput
  
              if (grade==-1) //  if statement if the sentinel value is set then stop
                  break;
  
              list.add(grade); // adds the grade from the grade variable to the LinkedList
              sum=sum+grade;// put the value of sum to sum and the new grade
  
              if (grade&gt;max) // if statement if grade is more than the max then sets max as the grade
                  max=grade;
              if (grade&lt;min) // if statement if grade is less than the min then sets min as the grade
                  min=grade;
  
              System.out.println("The course name: "+ course); // prints message of the course name entered
              System.out.println("Number of Scores :"+list.size()); // sits the number of scores using the size of the list
              System.out.printf("The Average Score: %.2f" ,(double)sum/list.size()); // calculates average to 2 decimal values using the sum divided by the length of the list
              System.out.println(); // goes to next line
              System.out.println("The Minimum Score: "+min); // sets the minimum value to min
              System.out.println("The Maximum Score :"+max);// sets the minimum value to min
              answer = JOptionPane.showConfirmDialog(null," Would you like to continue?"); // sets the value of the variable answer to confrim dialog box
          } while (answer == 0);  // sets the condition for do loop to answer == o so that it would continue only if the yes is selected
  
      }
  }
  </code></pre>