201k views
1 vote
Write a computer program that determines how many grades are between 0 and 19.

A list of 30 exam scores is: 31, 70, 92, 5, 47, 88, 81, 73, 51, 76, 80, 90, 55, 23, 43,98,36,87,22,61, 19,69,26,82,89,99, 71,59,49,64 Write a computer program that determines how many grades are between 0 and 19, between 20 and 39, between 40 and 59, between 60 and 79, and between 80 and 100. The results are displayed in the following form: Grades between 0 and 19: 2 students Grades between 20 and 39: 4 students Grades between 40 and 59: 6 students and so on. (Hint: use the command fprintf to display the results.)

User Fetsh
by
4.8k points

1 Answer

1 vote

Answer:

public class nnn {

public static void main(String[] args) {

int [] examScores = {31, 70, 92, 5, 47, 88, 81, 73, 51, 76, 80, 90, 55, 23, 43,98,36,87,22,61, 19,69,26,82,89,99, 71,59,49,64};

int zeroTo19 = 0;

int nineteenTo39 = 0;

int fortyTo59 = 0;

int sixtyTo79 = 0;

int eightyTo100 = 0;

for(int i =0; i<examScores.length; i++){

if(examScores[i]<=19){

zeroTo19++;

}

else if(examScores[i]>19&&examScores[i]<=39){

nineteenTo39++;

}

else if(examScores[i]>39&&examScores[i]<=59){

fortyTo59++;

}

else if(examScores[i]>59&&examScores[i]<=79){

sixtyTo79++;

}

else {

eightyTo100++;

}

}

System.out.println("0 - 19 is "+zeroTo19);

System.out.println("20 - 39 is "+nineteenTo39);

System.out.println("40 - 59 is "+fortyTo59);

System.out.println("60 - 79 is "+sixtyTo79);

System.out.println("80 - 100 is "+eightyTo100);

}

}

Step-by-step explanation:

  • This has been solved with Java
  • Create an array of the exam scores
  • Create new variables for each of the score range
  • Use multiple if statements as u loop through the array to determine the range of scores
  • Finally outside the loop print them variables out
User Ewhitt
by
4.7k points