为什么我的代码没有继续?

时间:2016-02-29 00:22:01

标签: java 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 个答案:

答案 0 :(得分: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);
}

如果您只想计算文件中男孩名字的数量。 否则,我不知道你在追求什么

编辑:你有无限循环,因为你没有从扫描仪中读取