i have code like this and i need specified output like i mentioned in bottom, sorry if my explanation isn't clear but here is my code:
public static int[] bubbleAscending(int x[], String y[], int z[]) {//sort by score
for (int i = 0; i < (z.length-1); i++) {
for (int j = 0; j < (z.length-i-1); j++) {
if (z[j] > z[j + 1]) {
int temp = z[j];
z[j] = z[j + 1];
z[j + 1] = temp;
}
}
}
return z;
}
public static void showArray(int[] x, String[] y, int[] z) {
for(int i= 0; i < x.length; i++) {
System.out.println(x[i]+" "+y[i]+" "+z[i]);
}
System.out.println("");
}
public static void main(String[] args) {
int number[] = {23,43,54,67,76};
String name[] = {"Angeline","Brian","Catherine","Daniel","Elliot"};
int score[] = {89,56,46,93,67};
System.out.println("********************");
System.out.println(" DATA ");
System.out.println("********************");
System.out.println(".:. Score Data : ");
System.out.println("------------------------------");
System.out.println("NUMBER Name Score");
System.out.println("------------------------------");
showArray(number,name,score);
nilai1 = bubbleAscending(number,name,score);
System.out.println("Data After Sorting");
System.out.println("********************");
System.out.println(" DATA ");
System.out.println("********************");
System.out.println(".:. Score Data : ");
System.out.println("------------------------------");
System.out.println("NUMBER Name Score");
System.out.println("------------------------------");
showArray(number,name,score);
}
i expected this output:
NUMBER Name Score //got right sorting for score
54 Catherine 46
43 Brian 56
76 Elliot 67
23 Angeline 89
67 Daniel 93
but my output:
NUMBER Name Score
23 Angeline 46
43 Brian 56
54 Catherine 67
67 Daniel 89
76 Elliot 93
now my question how to sort the number and name according to score? thanks