166k views
2 votes
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++;

1 Answer

3 votes

Answer:

Counting the number of elements in the array list smaller than temp.

Step-by-step explanation:

We have an array list,a previously initialized integer temp and a an integer c initialized with 0.

In the code a for loop is used to iterate over the array and it is checking if the element at jth index is less than temp if it is then increasing the variable c by 1.

Hence when the loop ends the c will be having the count of the integers in array list that are smaller than temp.

User Vadzim
by
8.4k points

Related questions