Ask Question

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);

+2
Answers (1)
  1. 26 September, 01:57
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers