我写了一个方法,每次看到一个新单词时都会给一个int调用添加1 total:
public int GetTotal() throws FileNotFoundException{
int total = 0;
Scanner s = new Scanner(new BufferedReader(new FileReader("Particles/Names.txt")));
while(s.hasNext()){
if(s.hasNext()){
total++;
}
}
return total;
}
Run Code Online (Sandbox Code Playgroud)
这是写它的正确方法吗?
java ×1