Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write the java code in simplest way. there should be only one class P6.5 Prime numbers. Write a program that prompts the user for

Please write the java code in simplest way.

there should be only one class

image text in transcribed

P6.5 Prime numbers. Write a program that prompts the user for an integer and then prints out all prime numbers up to that integer. For example, when the user enters 20, the program should print 2 3 5 7 11 13 17 19 Recall that a number is a prime number if it is not divisible by any number except 1 and itself. The modulus operator in Java is the percent character (%) - i.e (n%10 means modulus 10, for n=12345, 12345%10 means remainder when 12345/10 which would be 5) Use a class PrimeGenerator that gets the user input through the constructor with methods nextPrime and isPrime. The method isPrime returns true if the entered number is a prime. The method nextPrime return the next prime leading up to the input. The P6_5 class, has a main method that reads a positive integer as user input, constructs a PrimeGenerator object, and prints the primes

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions