Question: Write a Java program which takes in an int x and prints out the distance from x to the nearest prime number. A prime number

Write a Java program which takes in an int x and prints out the
distance from x to the nearest prime number. A prime number is
a number which is divisible only by itself and 1(e.g.2,3,5,7
etc.) If x is a prime, then the output should be 0.
Sample input
24
Sample output
1

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!