Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions