Ask Question

Assume an int array, candy, stores the number of candy bars sold by a group of children where candy[j] is the number of candy bars sold by child j. Assume there are 12 children in all, which of the following code could be used to compute the total number of bars sold by the children?

Scanner scan = Scanner. create (System. in); int value1 = scan. nextInt (); int value2 = scan. nextInt (); bars[value1] + = value2;

1. adds value1 to the number of bars sold by child value2

2. adds 1 to the number of bars sold by child value1 and child value2

3. adds 1 to the number of bars sold by child value1

4. inputs a new value for the number of bars sold by both child value1 and child value2

5. adds value2 to the number of bars sold by child value1

+1
Answers (1)
  1. 26 December, 03:15
    0
    5. adds value2 to the number of bars sold by child value1

    Explanation:

    First, the code snippet create a Scanner object called scan.

    Then it receive user input as value1. It then also receives another user input as value2.

    From the question, we are told that candy[j] is the number of candy bars sold by child j. So, value1 represent number of candy bars by child 1 and value2 represent number of candy bars by child 2.

    Therefore;

    bars[value1] + = value2;

    adds value2 to the number of bars sold by child value1
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Assume an int array, candy, stores the number of candy bars sold by a group of children where candy[j] is the number of candy bars sold by ...” 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