Advertisement
Latkoski

Lab01zad03

Feb 23rd, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. package zad2;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileReader;
  7. import java.io.IOException;
  8. import java.io.InputStreamReader;
  9.  
  10. public class zadaca3 {
  11.     public static void countWord(String path, String word) throws IOException {
  12.         File f = new File(path);
  13.         FileReader fr = new FileReader(f);
  14.         BufferedReader br = new BufferedReader(fr);
  15.         int count = 0;
  16.         String content = br.readLine();
  17.         String[] zborovi = content.split(" ");
  18.         for (int i = 0; i < zborovi.length; i++) {
  19.             if (zborovi[i].equals(word))
  20.                 count++;
  21.         }
  22.         System.out.println(count);
  23.     }
  24.  
  25.     public static void main(String[] args) throws IOException {
  26.         File f = new File("datoteka.txt");
  27.         String path = f.getAbsolutePath();
  28.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  29.         String word = br.readLine();
  30.         br.close();
  31.         countWord(path, word);
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement