int [][] div = {
{1, 1, 2},
{2, 1, 2},
{1, 2, 2},
{3, 1, 2},
{1, 2, 3},
{2, 1, 1},
{1, 1, 1}
};
I want to sort this array according to the first column.
I've done something but I messed up. I really don't know how to swap the other columns together with the first column.
for(int x = 0; x < div.length-1; x++) {
for(int y = 0; y < div.length-1;y++) {
if(div[y][0] > div[y+1][0]) {
tmp = div[y][0];
div[y][0] = div[y+1][0];
div[y+1][0] = tmp;
}
}
}
for(int x = 0; x < arr.length; x++) {
System.out.print(div[x][0]+" \t" + div[x][1] + "\t"+ div[x][2] + "\n");
}