Question: Listing 6.7, PrimeNumberMethod.java, provides the isPrime(int number) method for testing whether a number is prime. Use this method to find the number of prime numbers

Listing 6.7, PrimeNumberMethod.java, provides the isPrime(int number) method for testing whether a number is prime. Use this method to find the number of prime numbers less than 10000.

Listing 1 public class PrimeNumberMethod { public static void main(String[] args) {

Listing 1 public class PrimeNumberMethod { public static void main(String[] args) { System.out.printIn("The first 50 prime numbers are "); printPrimeNumbers(50); 2 public static void printPrimeNumbers(int numberofPrimes) { final int NUMBER_OF_PRIMES_PER_LINE - 10; // Display 10 per line int count - 0; / Count the number of prime numbers int number - 2; // A number to be tested for primeness 10 11 12 13 14 // Repeatedly find prime numbers while (count < numberofPrimes) { // Print the prime number and increase the count if (isPrime(number)) { count++; // Increase the count 15 16 17 if (count % NUMBER_OF_PRIMES_PER_LINE -- 0) { // Print the number and advance to the new 1line System.out.printf("%-5s ", number); 18 19 20 21 22 23 else System.out.printf("X-5s", number); 24 25 26 27 // Check whether the next number is prime number++; 28 29 30 31 /** Check whether number is prime */ public static boolean isPrime (int number) { for (int divisor - 2; divisor

Step by Step Solution

3.44 Rating (163 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Program plan Step 1 Create a test class called PrimeNumbersDem... View full answer

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 Java Programming Questions!