subject

The method countSorted is intended to find the length of the longest consecutive block of sorted values in an array, where sorted means that the next element in the array is higher than or equal to the previous element in the array. For example, if the array arr contains the values [25, 7, 7, 14, 14, 14, 21, 3, 3, 3, 5, 12, 12, 13, 13], the call countSorted(arr) should return 8, the length of the longest consecutive block of sorted numbers: 3, 3, 3, 5, 12, 12, 13, 13.

However, the method countSorted that you can see below does not work as intended.

Line 1: int countSorted(int[] array){
Line 2: int count = 1;
Line 3: int max = 1;
Line 4: for (int k = 1; k < array. length; k++) {
Line 5: if (array[k-1] <= array[k]) {
Line 6: count++;
Line 7: } else {
Line 8: if (count > max) {
Line 9: max = count;
Line 10: }
Line 11: count = 1;
Line 12: }
Line 13: }
Line 14: return max;
Line 15: }
Line 16: int [] arr = {25, 7, 7, 14, 14, 14, 21, 3, 3, 3, 5, 12, 12, 13, 13};
Line 17: System. out. println(countSorted(arr));

Enter the value printed on screen by this code segment (Line 17) ??

Which of the following changes should be made in the code so that the method works as intended?

a. It should return count instead of max
b. Before line 14, it should check if count is greater than max and, in that case, do max = count;
c. Before line 14, it should check if count is greater than max and, in that case, do max = count+1;
d. It should return max +1

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 08:30
Linda subscribes to a cloud service. the service provider hosts the cloud infrastructure and delivers computing resources over the internet.what cloud model is linda using
Answers: 1
question
Computers and Technology, 23.06.2019 00:20
Ihave been given the number of guns per 100, and the total firearm-related deaths per 100,000. i have to find the actual number of guns per country and actual number of gun-related deaths. if somebody could show me how to do 1 question, i can finish the rest, i am just confused. tia
Answers: 3
question
Computers and Technology, 23.06.2019 02:00
Read this excerpt from helen keller’s autobiography, the story of my life. have you ever been at sea in a dense fog, when it seemed as if a tangible white darkness shut you in, and the great ship, tense and anxious, groped her way toward the shore with plummet and sounding-line, and you waited with beating heart for something to happen? i was like that ship before my education began, only i was without compass or sounding-line, and had no way of knowing how near the harbour was. "light! give me light! " was the wordless cry of my soul, and the light of love shone on me in that very hour. . the morning after my teacher came she led me into her room and gave me a doll. the little blind children at the perkins institution had sent it and laura bridgman had dressed it; but i did not know this until afterward. when i had played with it a little while, miss sullivan slowly spelled into my hand the word "d-o-l-l." i was at once interested in this finger play and tried to imitate it. when i finally succeeded in making the letters correctly i was flushed with childish pleasure and pride. running downstairs to my mother i held up my hand and made the letters for doll. i did not know that i was spelling a word or even that words existed; i was simply making my fingers go in monkey-like imitation. in the days that followed i learned to spell in this uncomprehending way a great many words, among them pin, hat, cup and a few verbs like sit, stand and walk. based on this excerpt, which words best describe helen keller?
Answers: 2
question
Computers and Technology, 23.06.2019 02:30
These factors limit the ability to attach files to e-mail messages. location of sender recipient's ability to open file size of file type of operating system used
Answers: 2
You know the right answer?
The method countSorted is intended to find the length of the longest consecutive block of sorted val...
Questions
question
Chemistry, 10.06.2021 19:10
question
Advanced Placement (AP), 10.06.2021 19:10
question
Mathematics, 10.06.2021 19:10
Questions on the website: 13722363