import java.util.Scanner; public class NestedLoop { public static void main(String[] args) { Scanner input = new Scanner(System.in); String studentName; int grade = 0; int count = 0, total = 0; System.out.print("Enter student name (\"exit\" to leave): "); studentName = input.nextLine(); while (!studentName.equals("exit")) { // Reset count and total for this student's grades count = 0; total = 0; // Prompt for first grade System.out.print("Enter a grade (999 to leave): "); grade = input.nextInt(); while (grade != 999) { count++; total = total + grade; System.out.print("Enter a grade (999 to leave): "); grade = input.nextInt(); } System.out.println("Student " + studentName + " has an average grade of: " + total/count); input.nextLine(); //Prompt for student name System.out.print("Enter student name (\"exit\" to leave): "); studentName = input.nextLine(); } } }