I said "before"
See what is your problem you will exit the do while loop only when the user enter 999
But you prompt for the number of tests to enter and read only that number of tests
So when the user is supposed to enter the 999 ?
So use one of the two methods but not both
Your do while is kind of useless if you prompt for the number of test to enter
That one will work
java
import java.util.*;
import java.text.NumberFormat;
public class EnhancedTestScoreApp
{
public static void main(String[] args)
{
int scoreTotal = 0;
int scoreCount = 0;
int testScore = 0;
int maxScore = 0;
int minScore = 100;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of test scores to be entered: ");
int testNumber = sc.nextInt();
for (int i = 1; i <= testNumber; i++)
{
System.out.print("Enter score " + i + ": ");
testScore = sc.nextInt();
if (testScore <= 100)
{
scoreCount += 1;
scoreTotal += testScore;
if (testScore > maxScore)
{
maxScore = testScore;
}
if (testScore < minScore)
{
minScore = testScore;
}
}
// error message if entry above 100 or below 999
else if (testScore <=998)
{
System.out.println ("Invalid entry, not counted");
}
}
double averageScore = (double) scoreTotal / (double) scoreCount;
NumberFormat number = NumberFormat.getNumberInstance();
number.setMaximumFractionDigits(1);
String message = "\n" +
"Score count: " + scoreCount + "\n"
+ "Score total: " + scoreTotal + "\n"
+ "Average score: " + number.format(averageScore) + "\n"
+ "Highest test score: " + maxScore + "\n"
+ "Lowest test score: " + minScore + "\n";
System.out.println(message);
}
}