Question
Consider the following instance variable and method findLongest with line numbers added for reference. Method findLongest is intended to find the longest consecutive block of
Consider the following instance variable and method findLongest with line numbers added for reference. 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. (The same code is used in another question.) For example, if the array nums contains the values [7,10,10,15,15,15,15,10,10,10,15,10,10], the call find- Longest(10) should return 3, the length of the longest consecutive block of 10s. 1 private int[] nums; 2 public int findLongest(int target) { 3 int lenCount = 0; 4 int maxLen = 0; 5 for (int i = 0; i < nums.length; i++) { 6 if (nums[i] == target) { 7 lenCount++; 8 } else { 9 if (lenCount > maxLen) { 10 maxLen = lenCount; 11 } 12 } 13 } 14 if (lenCount > maxLen) { 15 maxLen = lenCount; 16 } 17 return maxLen; 18 }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get StartedRecommended Textbook for
Horngrens Financial and Managerial Accounting
Authors: Tracie L. Nobles, Brenda L. Mattison, Ella Mae Matsumura
5th edition
9780133851281, 013385129x, 9780134077321, 133866297, 133851281, 9780133851298, 134077326, 978-0133866292
Students also viewed these Programming questions
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
View Answer in SolutionInn App