Ask Question
19 March, 11:52

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.

+1
Answers (1)
  1. 19 March, 15:14
    0
    Java program given below

    Explanation:

    Java Code: Save this file as Main. java and keep This file and GenericQueue. java in same folder

    class Main {

    public static boolean isPrime (int n) {

    for (int i=2; i< = n/2; i++) {

    if (n % i= = 0)

    return false;

    }

    return true;

    }

    public static void main (String[] args) {

    GenericQueue queue = new GenericQueue ();

    int n = 0, p = 2;

    while (n < = 50)

    {

    if (isPrime (p))

    {

    queue. enqueue (p);

    n++;

    }

    p++;

    }

    System. out. println (queue);

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your 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. ...” in 📘 Engineering if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers