Question: Write a program that obtains the execution time for finding all the prime numbers less than 8,000,000, 10,000,000, 12,000,000, 14,000,000, 16,000,000, and 18,000,000 using the

Write a program that obtains the execution time for finding all the prime numbers less than 8,000,000, 10,000,000, 12,000,000, 14,000,000, 16,000,000, and 18,000,000 using the algorithms in Listings 22.5?22.7. Your program should print a table like this:10000000 8000000 12000000 14000000 16000000 18000000 Listing 22.5 Listing 22.6 Listing 22.7

Listing 22.5PrimeNumbers.java

import java.util.Scanner; 3 public class PrimeNumbers { public static void main(String[] args)

Listing 22.6EfficientPrimeNumbers.java

{ Scanner input = new Scanner(System. in); System.out.print("Find all prime numbers =

n, enter n: "); int n - input.nextInt (); 10 11 final

Listing 22.7SieveOfEratosthenes.java

int NUMBER_PER_LINE = 10; // Display 10 per line int count =

10000000 8000000 12000000 14000000 16000000 18000000 Listing 22.5 Listing 22.6 Listing 22.7 import java.util.Scanner; 3 public class PrimeNumbers { public static void main(String[] args) { Scanner input = new Scanner(System. in); System.out.print("Find all prime numbers = n, enter n: "); int n - input.nextInt (); 10 11 final int NUMBER_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 12 13 System.out.println("The prime numbers are:"); 14 15 16 // Repeatedly find prime numbers while (number

Step by Step Solution

3.34 Rating (175 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Program Plan Create a class Exercise2214 which contains method to print prime number calculation tim... 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!