So I am allowing the user to enter a 3 by 3 array and then the code should take the array and sort the integers based by columns. Such as:
[15, 87, 37,
55, 5, 22,
30, 12, 40]
becomes
[15, 5, 22,
30, 12, 37,
55, 87, 40]
Here is my method that seems to not work for the columns. It is instead sorting by row?
public static double[][] sortColumns(double[][] array)
{
double[][] sorted = array;
for(int x = 0; x < 3; x++)
{
Arrays.sort(sorted[x]);
} //end loops
return sorted;
} //end sortRows
I am not very familiar with coding so I do not 100% understand comparators that I saw some people use instead of .sort for this. If someone could be nice enough to help me out to solve this problem that would be great. Thank you.