Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that prints out as many primes as required that are larger than

ID: 3547109 • Letter: W

Question

Write a program that prints out as many primes as required that are larger than a value (including starting number) given by a user.

Note that the starting number must be positive (i.e. program should accept only values that are greater than 0 otherwise, ask user again to enter a positive number).

The program should loop until the user enters an acceptable number.

Now, it prints the first prime (strictly) larger than the number. Ask the user if he wants to print the next prime, if so print it out. Repeat until the user does not want any more primes

Explanation / Answer


private static void isPrime(int i) {


boolean prime = true;


for (int j = 2; j < i; j++) {


if (i % j == 0) {

prime = false;

break;

}

}


if (prime) {

System.out.println(i);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote