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
Get step-by-step solutions from verified subject matter experts
