Advertisement
jtentor

DemoQueue2 - DemoQueue2.java

May 17th, 2020
592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. import java.util.ArrayDeque;
  2. import java.util.LinkedList;
  3. import java.util.Queue;
  4. import java.util.Random;
  5.  
  6. public class DemoQueue2 {
  7.     public static void main(String[] args) {
  8.         System.out.print("Demo Queue - versión librería estándar\n");
  9.  
  10.         Queue<Integer> queue1 = new ArrayDeque<Integer>(10);
  11.         Queue<Integer> queue2 = new LinkedList<Integer>();
  12.  
  13.         Random random = new Random();
  14.  
  15.         int number;
  16.         int character;
  17.         System.out.println("Enqueuing...");
  18.         for (int c = 0; c < 10; ++c) {
  19.             queue1.add(number = random.nextInt(10001) - 5000);
  20.             queue2.add(character = random.nextInt(25) + 65);
  21.             System.out.printf("%d %c ", number, character);
  22.         }
  23.         System.out.print("\n");
  24.  
  25.         System.out.println("Dequeuing...");
  26.         while(queue1.size() > 0) {
  27.             System.out.printf("%d %c ", queue1.remove(), queue2.remove());
  28.         }
  29.         System.out.print("\n");
  30.  
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement