I am looking for the operator to enter two related data, then two more and so on continuously. When you need to search for a data, you can enter any of the two related data and the other data will be displayed. Ex: First and last name, if I write name, it gives me the last name.
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Ingrese el número de paises que va a ingresar: ");
int k = sc.nextInt();
String[][] dato = new String[2][k];
for (int i = 0; i < k; i++){
for (int j = 0; i < 2; j++){
if (j==0){
System.out.print("Ingrese el país: ");
dato[0][i] = sc.nextLine();
}
if (j==1){
System.out.print("Ingrese la capital: ");
dato[1][i] = sc.nextLine();
}
}
String search = null;
while (!"FIN".equals(search)){
System.out.println("Ingrese el dato a buscar: ");
search = sc.nextLine();
String resultado = Arrays.stream(dato)
.filter(s -> s.equals(dato))
.findFirst()
.orElse(null);
if (resultado != null) {
System.out.println("");
} else {
System.out.println("No Encontrado");
}
}
}
}
From the "while" I no longer know how to achieve the expected result.
Beforehand, I appreciate your help. Greetings.