Ask Question
20 May, 04:53

Array testGrades contains NUM. VALS test scores. Write a for loop that sets sumExtra to the total extra credit received. Full credit is 100, so anything over 100 is extra credit. Ex: If testGrades (101,83, 107,90), then sumExtra 8, because 1+0+7+0 is 8

import java. util. Scanner; 3 public class SumoFExcess (4 public static void main (String [ args) (Scanner scnr - new Scanner (System. in); final int NUM VALS - 4 int[] testGrades-new int[NUM VALS]; int ij int sunExtra 9999; 11 Assign sunExtra with 0 before your for loop 10 for (i-0; ǐ < testGrades. length; +.1) { testGrades[1]-scnr. nextInt) 12 14 15 / Your solution goes here 16 System. out. printin ("sumExtra:sumExtra);

+3
Answers (1)
  1. 20 May, 05:18
    0
    12. for (i = 0; i < testGrades. length; i+=1) {

    13. if (testGrades[i] > 100) {

    14. sumExtra = sumExtra + testGrades[i] - 100; }

    15. }

    Explanation:

    We first iterate through the entire testGrades array. For each test score that is in testGrades (that is testGrades[i]), we see whether or not the test grade is above 100 (See line 12). If test grade is greater than 100, this means we have extra credit. We simply subtract 100 from the test grade, add it with the previous value of sumExtra and store the value back in sumExtra (see line 14). Once i is greater than the length of the test grades, the loop is exited. We can now print sumExtra to obtain the result.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Array testGrades contains NUM. VALS test scores. Write a for loop that sets sumExtra to the total extra credit received. Full credit is ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers