Pessoal estou buscando formas de ordenar uma matriz em ordem crescente
Cheguei a essa, poderiam me dizer se existe uma lógica mais simples ?
public class ordenarMatriz {
public static void main(String [] args)
{
int[][] matriz = {{18,20,14},{2,7,19},{21,2,1}}; //inicialização valores matriz
int aux;
for (int x=0; x < matriz.length ; x++)
{
for (int y=0; y < matriz[x].length ; y++)
{
for (int a=0; a < matriz.length; a++)
{
for (int b=0; b < matriz[a].length ;b++)
{
if (matriz[a][b] >= matriz[x][y]) //ao final valores [x][y] == [2][2]
{
aux = matriz[x][y];
matriz[x][y] = matriz[a][b];
matriz[a][b] = aux;
}
}
}
}
}
for (int i=0; i < matriz.length ; i++)
{
System.out.println("");
for(int j = 0; j < matriz[i].length ; j++)
{
System.out.print(" "+matriz[i][j]);
}
}
}
}