Question: 2 Write a Java program given the following specification and provide comments which explain how your algorithm works. Estimate the Big O complexity of your

2 Write a Java program given the following specification and
provide comments which explain how your algorithm works.
Estimate the Big O complexity of your program and explain
your reasoning clearly.
Problem Statement
The goal is to read in a number N and output the distance
between the prime number that precedes it, and the prime that
follows it. If the number itself happens to be prime, then output
the distance to the subsequent prime. For example, if N is 7,
then output 4, because the next prime is 11, which is 4 away.
Input Format
An integer N.
Output Format
The distance between the preceding and subsequent prime
number at N.
Constraints
2N1000
Sample Input
10
Sample Output
4
 2 Write a Java program given the following specification and provide

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!