Question: Write a program that displays the first 50 prime numbers in ascending order. Use a generic queue given below to store the prime numbers. Also,

Write a program that displays the first 50 prime numbers in ascending order. Use a generic queue given below to store the prime numbers. Also, use the given method isPrime() to determine whether the number is prime or not.

public class GenericQueue { private java.util.LinkedList list = new java.util.LinkedList();

public void enqueue(E e){ list.addLast(e); }

public E dequeue(){ return list.removeFirst(); }

public int getSize(){ return list.size(); }

@override

public String toString(){

return "Queue: " + list.toString(); }

----------

public static boolean isPrime(int n){ for (int i=2; i<= n/2; i++){ if (n % i== 0) return false; } return true; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!