Question: Given a 2D of ints, return a string that shows the contents of the 2D array sorted in increasing order. For example, if the 2D

Given a 2D of ints, return a string that shows the contents of the 2D array sorted in increasing order. For example,

if the 2D array is { {9, -6}, {5, 2}, {-900, 5} },

then the method should return "-900 -6 2 5 5 9 "

There must exactly one space after each number, including the last one.

Remember to comment your program.

The Arrays class has many static methods. One method is sort and it works like this:

int [] a = { 6, -3, 47, 15 };

Arrays.sort( a );

for ( int num : a )

System.out.print( num + " " ); // -3 6 15 47

However, it cannot be used with a 2D array. Perhaps you can first copy everything from the 2D array into a 1D array.

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!