I am trying to make a program that will sort the array but keep track of their original indexes. I don't want to change the original array so I copied it into list[][].
   public static void main(String[] args) {
    int array[] = {17, 10, 8, 13, 5, 7, 8, 30};
    int list[][] = new int[8][2];
    int temp1, temp2, index, max;
    for(int i=0;i<array.length; i++){
        list[i][0]=array[i];
        list[i][1]=i;
    }
        for(int i=0; i <array.length-1; i++){
            max = list[i][0];
            index = i;
            for(int j = i+1; j<array.length;j++){
            if(max<list[j][0]){
                max = list[j][0];
                index = j;
            }
        }
            temp1 = list[i][0];
            temp2 = list[i][1];
            list[i][0]=max;
            list[i][1] = index;
            list[index][0]=temp1;
            list[index][1]=temp2;
        }
        for(int n=0; n<list.length;n++){
                System.out.println(list[n][0] + " " + list[n][1]);
        }
}
So it should print:
30 7
17 0
13 3
10 1
8 2
8 6
7 5
5 4
But when I run it, it prints:
30 7
17 7
13 3
10 7
8 6
8 7
7 7
5 4
Any suggestions?
 
     
     
     
    