Menu

[Solved] 4 Write Static Method Named Longestsortedsequence Accepts Array Integers Parameter Returns Q37170104

4. Write a static method named longestsortedSequence that accepts an array of integers as a parameter and that returns the lein java please

4. Write a static method named longestsortedSequence that accepts an array of integers as a parameter and that returns the length of the longest sorted (nondecreasing) sequence of integers in the array. For example, if a variable named array stores the following values: int [ ] array = {3, 8, 10, 1, 9, 14, -3, 0, 14, 207, 56, 98, 12); then the call oflongestSortedsequence (array) should return 4. Sample Output > run MyArray2 Enter Array length 13 Enter all the array elements on one line seperated by whitespaces 38 101914-30 14 207 56 98 12 because the longest sorted sequence in the array has four values in it (the sequence -3, 0, 14, 207) Notice that sorted means nondecreasing, which means that the sequence could contain duplicates. For example, if the array stores the following values: int array2 (17, 42, 3, 5, 5, 5, 8, 2, 4, 6, 1, 19) Then the method would return 5 for the length of the longest sequence (the sequence 3, 5, 5, 5, 8) Your method should return 0 if passed an empty array. Your method should return 1 if passed an array that is entirely in decreasing order or contains only one element. Show transcribed image text 4. Write a static method named longestsortedSequence that accepts an array of integers as a parameter and that returns the length of the longest sorted (nondecreasing) sequence of integers in the array. For example, if a variable named array stores the following values: int [ ] array = {3, 8, 10, 1, 9, 14, -3, 0, 14, 207, 56, 98, 12); then the call oflongestSortedsequence (array) should return 4. Sample Output > run MyArray2 Enter Array length 13 Enter all the array elements on one line seperated by whitespaces 38 101914-30 14 207 56 98 12 because the longest sorted sequence in the array has four values in it (the sequence -3, 0, 14, 207) Notice that sorted means nondecreasing, which means that the sequence could contain duplicates. For example, if the array stores the following values: int array2 (17, 42, 3, 5, 5, 5, 8, 2, 4, 6, 1, 19) Then the method would return 5 for the length of the longest sequence (the sequence 3, 5, 5, 5, 8) Your method should return 0 if passed an empty array. Your method should return 1 if passed an array that is entirely in decreasing order or contains only one element.

Expert Answer


Answer to 4. Write a static method named longestsortedSequence that accepts an array of integers as a parameter and that returns t… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *