this is a program that given in input 5 names and 5 telephone numbers gives in output the names with their numbers in alphabetical order. the problem is that when I give in input the first name and the first number, then the program jumps to the second "telephone number input" without making me insert the second name. I hope this makes sense.
also I wouldn't mind any suggestion to make the sorting easier.
this is the code:
import java.util.Arrays;
import java.util.Scanner;
public class RubricaTelefonica {
public static void main(String[] args) {
String names[] = new String[5];
long phone_num[] = new long[5];
Scanner sc = new Scanner(System.in);
for(int i = 0; i < 5; i++) {
System.out.println("Inserisci il nome:");
names[i] = sc.nextLine();
System.out.println("Inserisci il numero di telefono:");
phone_num[i] = sc.nextLong();
}
sc.close();
String names_unsorted[] = names;
Arrays.sort(names);
long sorted_num[] = new long[5];
for(int a = 0; a < 5; a++) {
//sorted cicle
for(int b = 0; b < 5; b++) {
//unsorted cicle
if(names[a] == names_unsorted[b]) {
sorted_num[a] = phone_num[b];
}
}
}
}
}