Need to adjust code so that it reads all of the words that it was tasked to find. for some reason it isn't finding all of the word locations in a text. for example the first question is to find "the" in romeo and juliet which should have 1137, but it's only picking up 1032?
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Scanner;
public class romeoJuliet {
public static void main(String[]args) throws Exception{
Scanner keyboard=new Scanner(System.in);
System.out.println("Enter a filename");
String fN=keyboard.nextLine();
int wLC=0, lC=0;
String sW= keyboard.nextLine();
File file=new File(fN);
String [] wordSent=null;
FileReader fO=new FileReader(fN);
BufferedReader buff= new BufferedReader(fO);
String sent;
while((sent=buff.readLine())!=null){
if(sent.contains(sW)){
wLC++;
}
lC++;
}
System.out.println(fN+" has "+lC+" lines");
System.out.println("Enter some text");
System.out.println(wLC+" line(s) contain \""+sW+"\"");
fO.close();
}
}
Need to adjust code so that it reads all of the words that it was tasked to find. for some reason it isn't finding all of the word locations in a text.
for example the first question is to find "the" in romeo and juliet which should have 1137, but it's only picking up 1032?
Trending now
This is a popular solution!
Step by step
Solved in 3 steps