나는 txt 파일을 읽고 특정 단어가 언급 된 횟수를 세는 간단한 Java 프로그램을 작성 중입니다. 이것은 아래에있는 것입니다. 컴파일되고 잘 실행되지만 수천 개로 잘 돌아갈 때 대답을 0으로 유지합니다 ...단어가 언급 된 횟수
이 경우에 "via via am"이 이 파일 ...
/*AUTHOR Yun Lee
Finding out the number of tweets per day*/
import java.io.*;
import javax.swing.*;
import java.util.Scanner;
class tweetnumber
{
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("tacobell.23jan2012.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
int counter1 = 0;
String s = "am via";
while ((strLine = br.readLine()) != null)
{
System.out.println (strLine);
if (strLine.contains(s))
{
counter1++;
}
}
in.close();
System.out.println("There were " + counter1 + " messages in the AM of this day");
}
catch (Exception e)
{
System.err.println("Error: " + e.getMessage());
}
}
}
파일이'println' 명령문에 의해 인쇄됩니까? 중단 점을 설정하고'strLine'을 검사하여 "am via"가 있는지 확인하려고 했습니까? – Blorgbeard
에 숙제로 태그를 지정해야합니까? 그건 그렇고, 찾고있는 끈이 연속으로 두 번 나타나면 어떻게 될까요? – jambriz
''via via "는 하나의 단어로만되어 있습니까? 아니면 "am"과 "via"라는 단어가 있는지 찾으려고합니까? –