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

Write a simple program that repeatedly will ask the user for an integer value, t

ID: 3612892 • Letter: W

Question

Write a simple program that repeatedly will ask the user for an integer value, then displays all prime numbers less than/equal to the particular integer value.


A positive number or -1 will end the program. 0 or any other negative number will cause the program to reprompt the user.

 

Use a do-while loop for user input, a for loop to test whether it is prime, and a while loop to iterate thru numbers from 2 to n, printing a row of output on ea. iteration. Use (tab) to line up the columns.

 

Sample Run                                                                                                                        
Welcome to the program!

########################################################

Enter a positive integer (-1 to quit): 6

Number    Is Prime  Counterexample

2         Yes       -

3         Yes       -

4         No        4 % 2 = 0

5         Yes       -

6         No        6 % 2 = 0

3 of the first 6 integers are prime; prime ratio = 0.5

Enter a positive integer (-1 to quit): 0

Enter a positive integer (-1 to quit): -2

Enter a positive integer (-1 to quit): 10

Number    Is Prime  Counterexample

2         Yes       -

3         Yes       -

4         No        4 % 2 = 0

5         Yes       -

6         No        6 % 2 = 0

7         Yes       -

8         No        8 % 2 = 0

9         No        9 % 3 = 0

10        No        10 % 2 = 0

4 of the first 10 integers are prime; prime ratio = 0.4

Enter a positive integer (-1 to quit): -1

Explanation / Answer

please rate - thanks without break and continue import java.util.*; public class prime {public static void main(String[] args) {int i,j,total,n; boolean not; Scanner in=new Scanner(System.in); System.out.println("Welcome to theprogram! ######################################################## "); do{ System.out.print("Enter a positive integer (-1 to quit):"); n=in.nextInt(); }while(n
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