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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started