182k views
4 votes
The following code accomplishes which of the tasks written below? Assume list is an int array that stores positive int values only.int foo = list[0];for (int j =1 ; j < list.length; j++) if (list[j] > foo) foo = list[j];

User DHW
by
9.2k points

1 Answer

4 votes

Answer:

The code mention in question will find "Largest Number in list"

Step-by-step explanation:

In first line of code

first element of array will be move in "foo" variable

then loop will start from 2nd value and ends at last value of array

in next step

2nd value of array compares with 1st value

If 2nd value is greater than 1st then greater value move into "foo" variable.

This process continues till the end of array.

after completion largest element of array will be present in "foo".

User Edward Kmett
by
8.9k points