我一直在做的这段代码假设每当代码在文件中找到一个术语时就添加一个计数器。计数器表示包含该术语的文档数量。计数器不起作用
System.out.println("Please enter the required word :");
Scanner scan2 = new Scanner(System.in);
String word2 = scan.nextLine();
String[] array2 = word2.split(" ");
for (int b = 0; b < array.length; b++) {
for (int i = 0; i < filename; i++) {
try {
BufferedReader in = new BufferedReader(new FileReader(
"C:\\Users\\user\\fypworkspace\\TextRenderer\\abc"
+ i + ".txt"));
int numDoc = 0;
int numofDoc = 0;
Scanner s2 = new Scanner(in);
{
while (s2.hasNext()) {
if (s2.next().equals(word2))
numDoc++;
}
}
if (numDoc > 0)
numofDoc++;
System.out.println("File containing the term is "
+ numofDoc);
} catch (IOException e) {
System.out.println("File not found.");
}
的输出是:
请输入所需的词语:
the
File containing the term is 1
File containing the term is 1
File containing the term is 1
File containing the term is 1
File containing the term is 1
File containing the term is 1
File not found
File containing the term is 1
File containing the term is 1
File containing the term is 1
File containing the term is 1
我想输出以显示包含术语文件的数量为10。
心指出我的错误?感谢..
虽然你已经取得了很大的意见,他们AREN”要解决他的问题,所以他们不属于答案。 – Gabe 2011-03-09 11:07:54
谢谢你的观点。当我从第二个for循环获取println后,numofDoc变量将被初始化。有什么建议?谢谢你借给我你的时间。 – 2011-03-09 11:15:24
@加贝这是家庭作业,我认为#3通过一点思考给解决问题带来了很好的线索。没有用于提供现成的解决方案。 – 2011-03-09 11:33:47