2016-02-29 70 views
-2

当我运行程序时,它提示我 “请输入包含女孩名字的文件名。” Then “请输入包含男孩名字的文件名称。” 并没有什么事情发生,但代码不会终止为什么我的代码不能继续?

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); 
    } 
+0

可能要添加到阅读'无限boysNames'。我认为你删除循环。 –

+1

所以你甚至没有添加任何调试来试图找出它自己? – John3136

+1

显示的代码中没有任何内容显示打印输入女孩消息或处理女孩输入的位置。 – pczeus

回答

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); 
} 

,如果你只是想统计文件中的男孩名字的数量。 否则,我不知道什么ü[R追求

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

相关问题