This is my code. I have fixed all errors I believe except that upon execution of the while loop it runs indefinitely.
Any ideas?
import java.util.Scanner; /*Write a program that prompts the user to enter the total number of students first. *Then ask the user to input each student’s grade and use loop statements to read in each grade. *Check input grade to make sure 0<=grade<=100, if the user input any other number, print out *warning message and ask the user to input a new grade. Display the highest score, *the lowest score and the average. */ public class LoopStatements { // Main Method public static void main(String[] args) { // Initialize int grade = 0; // grade value int numberofstudents = 0; // total number of students to be inputed int numberofgrades = 0; // number of grades for student being entered float total = 0; // sum of grades //Initialize int highest = 0; // running highest grade int lowest = 0; // running lowest grade double average = 0; // average of grades // Create Scanner Scanner input = new Scanner(System.in); // Prompt user to input total number of Students. System.out.println("Please enter the total number of Students: "); numberofstudents = input.nextInt(); //Set loop continuation to run for numberofstudents being entered. for (int i = 0; i < numberofstudents; i++) { // Prompt user to enter student grades. System.out.println("Please enter number of grades for Student: "); numberofgrades = input.nextInt(); //Set loop continuation to run for numberofgrades to be entered for that student. for (int j=0; j < numberofgrades; j++) { //Prompt user to enter a grade. System.out.println("Please enter Students' grade:"); grade = input.nextInt(); //Test to see if grade is valid if (grade < 0 || grade > 100) { System.out.println("Grade must be between 0 and 100.\nPlease enter another grade\n"); } while (grade >= 0 && grade <= 100) { //Determine if this is highest grade so far and store for highest if (grade > highest) { highest = grade; } //Determine if this is lowest grade so far and store for lowest if (grade < lowest) { lowest = grade; } total += grade; average = (total/numberofgrades); System.out.println("The highest grade is " + highest); System.out.println("The lowest grade is " + lowest); System.out.println("The average grade is " + average); } } } } }
--- Update ---
Ok, I see my first mistake.
While grade is this.... -> run this loop. I have nothing to tell it to leave the loop and return to the previous loop.