Ask Question
21 July, 18:37

Your program will search for prime numbers. You will first ask the user for the range of values to search, and use for loops to progress through all the numbers chosen. Note to determine if a number is a prime number, you must check to find out if there are any values besides 1 and itself that divide into it evenly. If any other numbers found then it is not prime. To check if any number is divisible, use the modulus operator which gives the value of the remainder of a division. List off all prime numbers found within a range given by the user. Do not list off numbers that are not prime. Also output at bottom the total number of primes from. See sample output at bottom of project sheet. Hint: first write the code that will determine if a given single number is prime or not, then put it in a larger loop. write in java.

+4
Answers (1)
  1. 21 July, 21:43
    0
    Java code is given below

    Explanation:

    import java. util. Scanner;

    public class Prime {

    public static void main (String args[]) {

    int first, last, flag = 0, i, j;

    Scanner s = new Scanner (System. in);

    System. out. println ("Enter the lower limit : ");

    first = s. nextInt ();

    System. out. println ("Enter the upper limit : ");

    last = s. nextInt ();

    System. out. println ("The prime numbers in between the entered limits are : ");

    int x = 0;

    for (i = first; i < = last; i++) {

    for (j = 2; j < i; j++) {

    if (i % j = = 0) {

    flag = 0;

    break;

    } else {

    flag = 1;

    }

    }

    if (flag = = 1) {

    x++;

    System. out. println (i + " ");

    }

    }

    System. out. println ("Total number of prime numbes between " + first + " and " + last + " are " + x);

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Your program will search for prime numbers. You will first ask the user for the range of values to search, and use for loops to progress ...” 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