So I am making a program that reads from my file and allows the user to enter a word to see the occurrence of the word. It runs properly but doesn't ask the user to enter a word and I'm stuck on why, here's the code:
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");
String fileName=scan.next().trim();
System.out.println("Enter the word you want to scan: ");
Scanner scr = new Scanner(new File(fileName));
// your code goes here ...
while(scr.hasNextInt()){
Scanner word2 = new Scanner(System.in);
String word1 = word2.next();
if (word1.equals(word2)){
word++;
}
}
System.out.println("Total words = " + word);
}
}