Ask Question

Write a program that prompts the user for an integer and then prints all prime numbers up to that integer.

+3
Answers (1)
  1. 2 January, 09:00
    0
    import java. util. Scanner;

    public class New

    {

    public static void main (String[] args)

    {

    int num;

    int prime;

    Scanner var=new Scanner (System. in);

    System. out. println ("Enter a number: ");

    num=var. nextInt ();

    for (int i=2; i
    {

    prime=0;

    for (int j=2; j
    {

    if (i%j==0)

    prime=1;

    }

    if (prime==0)

    System. out. println (i);

    }

    }

    }

    Explanation:

    Using Java Programming Language the program as implemented above will prompt a user to enter a number, for example the user enters 5,

    It will print

    2

    3

    which are the prime numbers up to the integer 5
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program that prompts the user for an integer and then prints all prime numbers up to that integer. ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers