Write an application that allows a user to enter any number of student test scores until the user enters 999. If the score entered is less than 0 or more than 100, display an appropriate message and do not use the score. After all the scores have been entered, display the number of scores entered, the highest score, the lowest score, and the arithmetic average.
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int total = 0;
int count = 0;
while (true){
System.out.println("Enter student test score: ");
int N=input.nextInt();
if (N == 999){
break;}
else if( N < 0 || N > 100){
System.out.println("Number is incorrect");
}
else{
total += N;
count += 1;}
}
double avg = total / count;
System.out.println("The average is:"+ avg);
System.out.println("There were " +count + " numbers entered");
}
}
Comments
Leave a comment