|
1234567891011121314151617181920 |
- import java.util.Scanner;
- import java.io.*;
-
- class Innlesing {
- public static void main(String[] args) throws FileNotFoundException {
- Scanner file = new Scanner(new File("winnie.txt"));
- Scanner s = new Scanner(System.in);
-
- System.out.println("What word?");
- String word = s.nextLine();
-
- int occurrences = 0;
- while (file.hasNextLine()) {
- if (file.nextLine().equals(word))
- occurrences += 1;
- }
-
- System.out.println("'"+word+"' was found "+occurrences+" times.");
- }
- }
|