I want a method to sort the parallel arrays according to the ascending order of names.
The code is working however the names I enter is not sorted by ascending order. What am I doing wrong?
public class SecA { //Method to store names,ages and marks for 10 people into parallel arrays public static void recAray(String[] name,int [] age,double[] mark) { for(int i=0;i<name.length;i++)//For loop to prompt to enter 10 names,ages and marks based on the names length array { Scanner in=new Scanner(System.in);//Creating Scanner object "in" to get input form the keyboard in the recAray method System.out.println("Enter name");//Prompting to enter name name[i]=in.nextLine(); System.out.println("Enter age");//Prompting to enter age age[i]=in.nextInt(); System.out.println("Enter mark");//Prompting to enter age mark[i]=in.nextDouble(); //Displaying names, ages and marks in array element [i] System.out.println("Person is:"+" "+name[i]+" "+"Age is:"+" "+age[i]+" "+" "+"Mark is:"+ " "+mark[i]); } } //Method to sort the parallel arrays according to the ascending order of names. public void sortD (String[] name, int[] age, double[] mark) { for (int i = 0; i < age.length - 1; i++) { for (int j = 0; j < age.length -1-i; j++) { if (age[j] > age[j + 1]) { /* *Swap age with lowest age */ int ageTemp = age[j]; age[j] = age[j + 1]; age[j + 1] = ageTemp; /* * Swap name using the same index * of the age */ String nameTemp = name[j]; name[j] = name[j + 1]; name[j + 1] = nameTemp; /* * Swap marks using the same index * of the age */ double markTemp=mark[j]; mark[j]= mark[j + 1]; mark[j + 1]=markTemp; } } }