Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.PriorityQueue;
- import java.util.Scanner;
- public class SuperCool
- {
- static PriorityQueue<String> queue = new PriorityQueue<String>();
- public static void main(String[] args)
- {
- Scanner sc = new Scanner(System.in);
- while(true)
- {
- System.out.print("Skriv inn setning:\t");
- addElements(sc.nextLine());
- }
- }
- public static void printTenElements()
- {
- for(int i = 0; i < 10; i++)
- System.out.print(queue.poll()+" ");
- }
- public static void addElements(String sentence)
- {
- String[] words = sentence.split(" ");
- for(String word : words)
- {
- if(queue.size()>=10)
- printTenElements();
- queue.offer(word);
- }
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment