I need to use the Scanner class to read a file and count how many times a words repeats, but I need to know in which line the word is repeated. Let’s say:
Jack goes to school
Jane goes to the gym
I need to keep a record like this
Jack 1
goes 1, 2
to 1, 2
school 1
Jane 2
the 2
gym 2
Any ideas? I’m not familiar with the Scanner class and I know I can use scanner.next() to read each word but I don’t know how to know if the word is in a new line.
Think about the problem in two steps. What if you read one line at a time and then start parsing words within the line? That way you know what line # you are on but don’t lose the benefits of parsing using Scanner.
There are a few ways to accomplish part 1. I’ll refrain from posting those in case this is homework.