Guest User

Untitled

a guest
Feb 6th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import java.util.PriorityQueue;
  2. import java.util.Scanner;
  3. public class SuperCool
  4. {
  5.     static PriorityQueue<String> queue = new PriorityQueue<String>();
  6.  
  7.     public static void main(String[] args)
  8.     {
  9.         Scanner sc = new Scanner(System.in);
  10.  
  11.         while(true)
  12.         {
  13.             System.out.print("Skriv inn setning:\t");
  14.             addElements(sc.nextLine());
  15.         }
  16.     }
  17.  
  18.     public static void printTenElements()
  19.     {
  20.         for(int i = 0; i < 10; i++)
  21.             System.out.print(queue.poll()+" ");
  22.     }
  23.  
  24.     public static void addElements(String sentence)
  25.     {
  26.         String[] words = sentence.split(" ");
  27.         for(String word : words)
  28.         {
  29.             if(queue.size()>=10)
  30.                 printTenElements();
  31.             queue.offer(word);
  32.         }
  33.         System.out.println();
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment