Question: JAVA --- An integer is said to be prime if it is divisible only by 1 and iteself. For example, 2, 3, 5, and 7

JAVA --- An integer is said to be prime if it is divisible only by 1 and iteself. For example, 2, 3, 5, and 7 are prime, but 4, 6, 8, and 9 are not. Please give the solution to the following sub-questions (3 pts).

a) Write a method, isPrime(), that determines if a number is prime.

b) Use this method in the main() that determines whether user input is prime or not. The main() includes a while loop which continuously reads user input until user types-999 as the sentinel value and checks whether the input value is prime. Within the while loop, please print the input value with the result from the isPrime() method.

c) Unlike the above case, please use Random class to generate random numbers and use 0 as the exit condition of the while loop.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!