Ask Question
4 March, 01:29

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

+3
Answers (1)
  1. 4 March, 04:01
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers