Andziev

HW01_4

Mar 12th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.Arrays;
  3.  
  4. public class HW01_4 {
  5.     public static void main(String[] args) throws IOException {
  6.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  7.         String path = reader.readLine();
  8.         String word = reader.readLine();
  9.  
  10.         File file = new File(path);
  11.         BufferedReader input = new BufferedReader(new FileReader(file));
  12.  
  13.         long occurrences = input.lines()
  14.                 .flatMap(f -> Arrays.stream(f.trim().split(" ")))
  15.                 .map(m -> m.toUpperCase())
  16.                 .filter(f -> f.length() > 0&&f.equals(word.toUpperCase()))
  17.                 .count();
  18.  
  19.         System.out.print(occurrences);
  20.     }
  21. }
Add Comment
Please, Sign In to add comment