OK i have been stuck with this particular problem and driving me crazy any insight would be helpful. I am trying to create a program that asks user for a string and using the scanner method count the instances it appears in a txt file below is the code oh the professor didnt want bufferread just plain scanner.
package scanner;
import java.io.*;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException
{
// this is for the user to input string
Scanner keyboard = new Scanner(System.in);
System.out.print("what do you want to search for: ");
String input = keyboard.nextLine();
//this is path of file
Scanner mob = new Scanner
("C:\\Users\\Eduardo Dennis\\Documents\\cdi.txt");
int counter = 0;
// this is supposed to go through every word and if the input
matches any string in the path to counter and repeat loop untill
end of file at which it prints counter how many instances of the
word it found, in theory all is well but it does not do it !
while (mob.hasNext())
{
if (mob.equals(input));
counter++;
}
System.out.println(counter);
}
}
I would be greatful if someone would help me thanks in advance