Java Fundamentals Challenge: Build a Grade Average Checker
• Updated 3/9/2026 • javafundamentalsbeginner coding challengescannerconditionalsarithmeticinput validation
Problem statement
A teacher wants a simple program that can quickly check a student's performance based on three quiz scores. Your task is to build a Java program that asks the user to enter three scores, calculates the average, and displays whether the student passed or failed.
A student passes if the average score is 75 or higher. If any score is invalid, the program should show a clear error message instead of continuing.
Input and output expectations
- Input: three quiz scores entered by the user
- Input: each score should be a number from 0 to 100
- Output: the calculated average
- Output: either Passed or Failed
- Output: an error message if the input is not valid
Constraints
- Do not use file input or file output
- Do not use databases or network requests
- Each score must be between 0 and 100
- The program must stop and show an error if the user enters invalid data
- Use only beginner-friendly Java concepts
Hints
- Use Scanner to read values from the user
- Store each score in its own variable
- Check that each value is numeric before using it
- Use a simple formula to compute the average
- Use an if-else statement to decide if the student passed or failed
Solution explanation
Start by asking the user to enter three quiz scores. Before saving each value, make sure the input is actually a number. This prevents the program from crashing when the user enters text.
After reading the scores, check whether each one is between 0 and 100. If any score is outside that range, show an error message and stop the program.
If all scores are valid, add them together and divide by 3.0 to get the average. Then compare the average to 75. If it is 75 or higher, print Passed. Otherwise, print Failed.
Solution
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter score 1: ");
if (!scanner.hasNextDouble()) {
System.out.println("Error: Score 1 must be a number.");
return;
}
double score1 = scanner.nextDouble();
System.out.print("Enter score 2: ");
if (!scanner.hasNextDouble()) {
System.out.println("Error: Score 2 must be a number.");
return;
}
double score2 = scanner.nextDouble();
System.out.print("Enter score 3: ");
if (!scanner.hasNextDouble()) {
System.out.println("Error: Score 3 must be a number.");
return;
}
double score3 = scanner.nextDouble();
if (score1 < 0 || score1 > 100 ||
score2 < 0 || score2 > 100 ||
score3 < 0 || score3 > 100) {
System.out.println("Error: Scores must be between 0 and 100.");
return;
}
double average = (score1 + score2 + score3) / 3.0;
System.out.printf("Average: %.2f%n", average);
if (average >= 75) {
System.out.println("Passed");
} else {
System.out.println("Failed");
}
}
}
/*
Sample Output:
Enter score 1: 80
Enter score 2: 70
Enter score 3: 90
Average: 80.00
Passed
*/
Variations or next challenges
- Ask for five scores instead of three
- Display a letter grade such as A, B, C, D, or F
- Show the highest and lowest score entered
- Allow the user to check multiple students in one run
- Count how many scores are passing and how many are failing
Related snippets or guides
- Java variables and data types
- Using Scanner for user input
- Basic arithmetic operations
- If-else statements
- Input validation
- Formatted output with printf

