-2

When I run the program it Prompts me to "Please enter the file name containing the the girls names." Then "Please enter the file name containing the the boy names." and nothing else happens but the code doesn't terminate

    public static int getBoys(ArrayList<String> boysNames, Scanner s)         throws IOException
    {
        //Getting boys file location
    System.out.println("Please enter the file name containing the the  boys names.");
    String boyFileLocation=s.nextLine();

    //Opening the file containing the names of boys
    File boyFile = new File(boyFileLocation);
    Scanner BF = new Scanner(boyFile);
    int initialBoyCount=0;

    while(BF.hasNext())
    {
    for (int i=0;i<boysNames.size();i++)
    {
        if(BF.nextLine()==boysNames.get(i))
    {

    }
    else
    {
        boysNames.add(BF.nextLine());
    }
    }
    }
    return(initialBoyCount);
    }

1 Answers1

0
public static int getBoys(ArrayList<String> boysNames, Scanner s)         throws IOException
{
    //Getting boys file location
System.out.println("Please enter the file name containing the the  boys names.");
String boyFileLocation=s.nextLine();

//Opening the file containing the names of boys
File boyFile = new File(boyFileLocation);
Scanner BF = new Scanner(boyFile);
int initialBoyCount=0;

while(BF.hasNext())
{ BF.next() initialCount++;
}
return(initialBoyCount);
}

if you are just want to count number of boy names in the file. Otherwise, i have no idea what u r pursuing

Edit: and you had infinite loop cause you didn't read from the scanner

RinaLiu
  • 400
  • 2
  • 9