0
所以我的程序知道文件的位置,它可以读取它有多少个单词,但是,我试图比较单词来计算单词的出现次数,与扫描仪一起使用。 该程序说,我不能将字符串转换为布尔值,我明白,但我会怎么做到这一点? 我可以得到一个答案,为什么它运行,但不会让我找到这个词来寻找 感谢我的程序从文件中读取,但无法找到文字
import java.util.*;
import java.io.*;
public class wordOccurence {
public static void main(String[] args) throws IOException {
{
int wordCount=0;
int word =0;
Scanner scan=new Scanner(System.in);
System.out.println("Enter file name");
System.out.println("Enter the word you want to scan");
String fileName=scan.next().trim();
Scanner scr = new Scanner(new File(fileName));
// your code goes here ...
while(scr.nextLine()){
String word1 = scr.next();
if (word1.equals(scr)){
word++;
}
}
System.out.println("Total words = " + word);
}
}
}