176k views
1 vote
Write a program to calculate the average of all scores entered between 0 and 100. Use a sentinel-controlled loop variable to terminate the loop. After values are entered and the average calculated, test the average to determine whether an A, B, C, D, or F should be recorded. The scoring rubric is as follows: A—90-100; B—80-89; C—70-79; D—60-69; F < 60

1 Answer

4 votes

Answer:

import java.util.Scanner;

public class ANot {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

int n =0;

int sum=0;

while(n<=100){

System.out.println("enter the next score");

sum = sum+in.nextInt();

n++;

}

double average = sum/n;

if(average>90){

System.out.println("Record A");

}

else if(average>80 && average<90){

System.out.println("Record B");

}

else if(average>70 && average<80){

System.out.println("Record C");

}

else if(average>60 && average<70){

System.out.println("Record D");

}

else{

System.out.println("Record F");

}

}

}

Step-by-step explanation:

Using Java programming language:

  1. Prompt user to input the 100 scores.
  2. Use a while statement with the condition while(n<100) since n has been initialized to zero. Increment n after each iteration.
  3. create a sum variable outside the while loop and initialize to zero
  4. Add the value entered at each iteration to the sum variable
  5. average = sum/n
  6. Use multiple if/elseif and else statements to output what should be recorded according to the given rubic.
User Anhquan
by
5.6k points