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?
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)