Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Explain consumer behaviour.

Answered: 1 week ago

Question

Explain the factors influencing consumer behaviour.

Answered: 1 week ago