【发布时间】:2016-02-29 08:38:27
【问题描述】:
当我运行程序时,它会提示我 “请输入包含女孩名字的文件名。” 然后 “请输入包含男孩名字的文件名。” 没有其他反应,但代码没有终止
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);
}
【问题讨论】:
-
可能你正在无限地添加到
boysNames。我认为您删除了 for 循环。 -
所以你甚至没有添加任何调试来尝试自己解决?
-
您的代码中没有任何内容显示您打印输入女孩消息或处理女孩输入的位置。
-
没有冒犯,但是您的代码很糟糕,即使您的代码确实有效,也不显示任何逻辑,您总是会返回 0