Question: 1 1 - 1 6 : Consider the following data field and method findLongest. Method findLongest is intended to find the longest consecutive block of

11-16: Consider the following data field and method findLongest. Method findLongest is intended to find the longest consecutive block of the value target occurring in the array nums; however, findLongest does not work as intended. For example, if the array nums contains the values [7,10,10,15,15,15,15,10,10,10,15,10,10], the call findLongest(10) should return 3, the length of the longest consecutive block of 10s. Which of the following best describes the value returned by a call to findLongest?
private int[] nums;
public int findLongest(int target)
{
int lenCount =0;
int maxLen =0;
for (int k =0; k < nums.length; k++)
{
if (nums[k]== target)
{
lenCount++;
}
else
{
if (lenCount > maxLen)
{
maxLen = lenCount;
}
}
}
if (lenCount > maxLen)
{
maxLen = lenCount;
}
return maxLen;
}
A. It is the length of the array nums.
B. It is the length of the first consecutive block of the value target in nums.
C. It is the length of the shortest consecutive block of the value target in nums.
D. It is the number of occurrences of the value target in nums.
E. It is the length of the last consecutive block of the value target in nums.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!