University stuff.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Innlesing.java 486B

1234567891011121314151617181920
  1. import java.util.Scanner;
  2. import java.io.*;
  3. class Innlesing {
  4. public static void main(String[] args) throws FileNotFoundException {
  5. Scanner file = new Scanner(new File("winnie.txt"));
  6. Scanner s = new Scanner(System.in);
  7. System.out.println("What word?");
  8. String word = s.nextLine();
  9. int occurrences = 0;
  10. while (file.hasNextLine()) {
  11. if (file.nextLine().equals(word))
  12. occurrences += 1;
  13. }
  14. System.out.println("'"+word+"' was found "+occurrences+" times.");
  15. }
  16. }