The task was to create a program which organises a users name with their corresponding mark and displays this in descending order. I'm asking how to sort both arrays at the same time but only by comparing the elements of one of the arrays. As a restriction, I cannot use classes, only associated arrays.
int [] ArrMarks = new int [5];
String [] ArrNames = new String [5];
Button to Accept user input
for (int i = 0; i < 5; i++)
{
ArrNames[i] = JOptionPane.showInputDialog("Enter a Name:");
ArrMarks[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter a mark:"));
}
Display button including the part which sorts the code, this is the main part I am unsure of.
int Hi = ArrMarks[0];
for(int i = 0; i < 5; i++) {
if(ArrMarks[i] > Hi) {
Hi = ArrMarks[i];
}
}
txaDisplay.append("Names:"+"\t\t"+"Marks");
for (int i = 0; i < 5; i++) {
txaDisplay.append(ArrNames[i]+"\t\t"+ArrMarks[i]+"\n");
}