Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.LinkedList;
- /**
- * Created by Nemanja on 31-Aug-15.
- */
- public class kosta
- {
- public static void main(String[] args)
- {
- BufferedReader reader = null;
- try
- {
- reader = new BufferedReader(new FileReader("tekst.txt"));
- String[] splitter;
- LinkedList<String> list = new LinkedList<String>();
- String s;
- int[] wordCount;
- while ((s = reader.readLine()) != null)
- {
- splitter = s.split(" ");
- for (int i = 0; i < splitter.length; i++)
- {
- list.add(splitter[i]);
- }
- }
- Collections.sort(list);
- wordCount = new int[list.size()];
- for (int i = 0; i < wordCount.length; i++)
- {
- wordCount[i] = 1;
- }
- int j = 0;
- for (int i = 1; i < list.size(); i++)
- {
- while (i < list.size() && list.get(i).equals(list.get(i - 1)))
- {
- wordCount[j]++;
- i++;
- }
- j++;
- }
- for (int i : wordCount)
- {
- if(wordCount[i] != 0)
- System.out.println(wordCount[i]);
- }
- } catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement