This is actually a 2-part question. Below is my code so far and I'm trying to read two files (girlnames.txt, and boynames.txt) and store the information in those files into arrays. The information in the files are both in this format: "Name 20123" without the parentheses.

My first issue is that I get an InputMismatchException on line 19 which is the line:

girlRegNumber[i] = input.nextInt();

I'm trying to store the name in the first array and the number following it in the array that the error resides in.

The above is my biggest issue right now, but if possible I need help at the end of my program where I am trying to search the two arrays that I'm making for a name and then eventually I will write more code to do something with the name and number but I can handle that.

Thanks for anyone who can help me and please let me know if I wasn't clear enough about what I'm trying to accomplish here.


Java Code:
import java.util.*;
import java.io.*;

public class PopularNameSearch {
  public static void main (String [] args) {
    Scanner scn = new Scanner(System.in);
    String[] girlNames = new String[999];
    String[] boyNames = new String[999];
    int[] girlRegNumber = new int[999];
    int[] boyRegNumber = new int[999];
    
    try {         
        Scanner input = new Scanner(new FileInputStream("girlnames.txt"));
        while (input.hasNext()) {  
          for(int i=0;i<999;i++) {
            girlNames[i] = input.next();
          }
          for(int i=0;i<999;i++) {
            girlRegNumber[i] = input.nextInt();
          }
        }

        Scanner input2 = new Scanner(new FileInputStream("boynames.txt"));
        while (input2.hasNext()) {
          for(int i=0;i<999;i++) {
            boyNames[i] = input2.next();
          }
          for(int i=0;i<999;i++) {
            boyRegNumber[i] = input2.nextInt();
          }
        }
      }
      catch(Exception fnfe) {
        fnfe.printStackTrace();  
      }
    
    boolean fin = true;    
    while (fin) {
      System.out.println("Please enter a name to search the database or 1 to quit the program:");
      String name = scn.nextLine();
      
      if (name=="1") {
        fin = false;
        System.exit(0);
      } else {
        for (String g : girlNames) {
          if (g.contains(name)) {
            System.out.println(g);
          }
        }
        for (String b : boyNames) {
          if (b.contains(name)) {
            System.out.println(b);
          }
        }
      }
    }
  }
}