Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zad2;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class zadaca3 {
- public static void countWord(String path, String word) throws IOException {
- File f = new File(path);
- FileReader fr = new FileReader(f);
- BufferedReader br = new BufferedReader(fr);
- int count = 0;
- String content = br.readLine();
- String[] zborovi = content.split(" ");
- for (int i = 0; i < zborovi.length; i++) {
- if (zborovi[i].equals(word))
- count++;
- }
- System.out.println(count);
- }
- public static void main(String[] args) throws IOException {
- File f = new File("datoteka.txt");
- String path = f.getAbsolutePath();
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- String word = br.readLine();
- br.close();
- countWord(path, word);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement