Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What does the following code do? Assume list is an array of int values, temp is

ID: 3877687 • Letter: W

Question

What does the following code do? Assume list is an array of int values, temp is some previously initialized int value, and c is an int initialized to 0.

for (int j = 0; j < list.length; j++)

          if (list[j] > temp) c++;

Question 13 options:

It finds the smallest value and stores it in temp

It counts the number of elements equal to the smallest value in list

It counts the number of elements in list that are greater than temp

It counts the number of elements in list that are less than temp

A)

It finds the smallest value and stores it in temp

B)

It counts the number of elements equal to the smallest value in list

C)

It counts the number of elements in list that are greater than temp

D)

It counts the number of elements in list that are less than temp

Explanation / Answer

Answer

C) It counts the number of elements in list that are greater than temp

Explanation:- firstly the loop execute until the length of the list is not end .in the loop the all elements of the list is compared to the temp variable,if the value of list is greater than temp then it increases the value of temp,so it count the number of elements that is greater than temp.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote