Question: Write it in java Ask user to give a positive number and report back if it is prime.To test if a single number is prime,

Write it in java

Ask user to give a positive number and report back if it is prime.To test if a single number is prime, you need to test if any number smaller than it can be divided evenly into it. To know if an individual number X is evenly divisible by Y, the remainder from a division of X/Y is zero.We can use the modulus operator, Example:if (X % Y == 0 )then it is divisible.You may want to create a variable to keep track of how many numbers are evenly divisible into the users number. Use a loop to cycle through the division. Once you have this part working, put the whole thing in a larger loop that will allow the program to run continuously unless 0 is entered. Inform the user that they must enter 0 in order to end the program. Sample output: Enter a positive number to see if it is prime. Enter a 0 to end the program. >>>17 This is a prime number. Enter a positive number to see if it is prime. Enter a 0 to end the program. >>>0 Goodbye. Please do it by using simple while,if or for loops

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!