The following code accomplishes which of the tasks written below? Assume list is
ID: 3877688 • Letter: T
Question
The following code accomplishes which of the tasks written below? Assume list is an int array that stores positive int values only.
int foo = 0;
for (int j =0 ; j < list.length; j++)
if (list[j] > foo) foo = list[j];
Question 14 options:
It stores the smallest value in list (the minimum) in foo
It stores the largest value in list (the maximum) in foo
It stores every value in list, one at a time, in foo, until the loop terminates
It counts the number of elements in list that are greater than foo
A)It stores the smallest value in list (the minimum) in foo
B)It stores the largest value in list (the maximum) in foo
C)It stores every value in list, one at a time, in foo, until the loop terminates
D)It counts the number of elements in list that are greater than foo
Explanation / Answer
int foo = 0;
// Initially foo is initialized with the value 0.
for (int j =0 ; j < list.length; j++)
if (list[j] > foo) foo = list[j];
This loop executes for the no of times the list having numbers in it.
After executing this block of code the foo will, holds the maximum element which contained in the list
So the answer is
It stores the largest value in list (the maximum) in foo
____________________Thank You
B)It stores the largest value in list (the maximum) in foo
____________________Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.