0%
0 / 6 answered

Introduction to Using Data Sets Practice Test

6 Questions
Question
1 / 6
Q1

A store tracks weekly sales in an int[] and uses totals for restocking decisions. Consider:

At a pop-up snack shop, the owner logs daily granola bar sales for a 7-day event to decide whether to reorder more inventory. Because the event lasts exactly one week, an array is used where each element stores one day’s sales. When a counting mistake is found, the owner must modify one element and then recompute totals to make an accurate reorder decision.


int[] dailySales = {20, 18, 22, 19, 25, 21, 17};

int total = 0;

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

    total += dailySales<u>i</u>; // add each day

}

System.out.println(total);

Refer to the problem scenario in the passage, identify the error in the code snippet and suggest a fix.

Question Navigator