Question: Task 2 Write a static method public static boolean is Sorted (int[] a) that checks whether each one-dimensional sub-array of a two-dimensional array is sorted

 Task 2 Write a static method public static boolean is Sorted

Task 2 Write a static method public static boolean is Sorted (int[] a) that checks whether each one-dimensional sub-array of a two-dimensional array is sorted in increasing order. For instance, for int[u a = {{1, 2, 3, 4, 5, 5}, {2, 3, 4}}; the method should return true (since the two sub-arrays are sorted). Likewise for the empty array intnb = {}; it should return true (since all subarrays -- which means for the empty array, none has to be checked - are sorted). But for int[] c = {{1}, {2, 1, 3, 4}}; it should return false (since the subarray {2, 1, 3, 4} is not sorted). You may write (an) auxiliary method(s). Test your program with the three examples above in a main method. Also, comment your code to explain the main parts of your logic. [25 marks)

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 Databases Questions!