0%
0 / 9 answered

Algorithms with Selection and Repetition Practice Test

9 Questions
Question
1 / 9
Q1

A school stores grades in an int[] gradeList; the algorithm iterates to compute average and count grades >= threshold. Inputs are gradeList and threshold; outputs are average and countAbove. Example input: 80, 90, 70, threshold 85; output: average 80.0, countAbove 1. Example input: 100, 60, threshold 70; output: average 80.0, countAbove 1.


// Compute average and count grades at or above threshold

int sum = 0;

int countAbove = 0;

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

    sum += gradeList<u>i</u>;

    if (gradeList<u>i</u> >= threshold) {

        countAbove++;

    }

}

double average = (double) sum / gradeList.length;

System.out.println(average + "," + countAbove);

Consider the algorithm for processing grades; which part ensures every grade is compared to threshold exactly once?

Question Navigator