Very beginner level code help needed.
This code should display "incorrect entry" if a entry is not <=100 or =999. I think my code is in the wrong area but can't figure it our where it goes.
public class ModifiedTestScoreApp
public static void main(String args)
// display operational messages
System.out.println("Please enter test scores that range from 0 to 100.");
System.out.println("To end the program enter 999.");
System.out.println(); // print a blank line
// initialize variables and create a Scanner object
double scoreTotal = 0;
int scoreCount = 0;
int testScore = 0;
Scanner sc = new Scanner(System.in);
// get a series of test scores from the user
while (testScore <= 100)
// get the input from the user
System.out.print("Enter score: ");
testScore = sc.nextInt();
// accumulate score count and score total
if (testScore <= 100)
scoreCount = scoreCount + 1;
scoreTotal = scoreTotal + testScore;
else if (testScore != 999)
System.out.println("Invalid entry, not counted");
// display the score count, score total, and average score
double averageScore = scoreTotal / scoreCount;
String message = "\n"
+ "Score count: " + scoreCount + "\n"
+ "Score total: " + scoreTotal + "\n"
+ "Average score: " + averageScore + "\n";
Re: Very beginner level code help needed.
What does the code do now when it is compiled and executed?
Show the program's input and output and add some comments saying what the output should be.
Suggestion: Print out the value of testScore at the end of the error message so you can see what the bad value is.