Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Recall that a prime number is any integer >1 that is evenly divisible only by itself and 1. The Sieve of Eratosthenes is a method

image text in transcribed
image text in transcribed
image text in transcribed
Recall that a prime number is any integer >1 that is evenly divisible only by itself and 1. The Sieve of Eratosthenes is a method for finding primes. It operates as follows: a) Create an array with all elements initialized to true. Array elements with prime subscripts (indices) will remain true. All other array elements will eventually be set to false. b) Starting with array subscript 2 (because I is not prime), every time an array element is found whose value is true, loop through the remainder of the array and set to false every element whose index is a multiple of the index for the element with value true (1). For array index 2, all elements beyond 2 in the array that are multiples of 2 (1.c., 4, 6, 8, 10 ...) will be set to false (these numbers are not prime since they are divisible by 2). For array index 3, all elements beyond 3 in the array that are multiples of 3 (i.e., 6, 9, 12, 15, etc.) will be set to false; and so on. When this process completes, the array elements that remain true indicate that the index is a prime number (since these numbers were not crossed off the list as being multiples of some other number). These indices can then be printed. Write a program that uses an array of 1000 elements to determine and print the prime numbers between 1 and 999. Ignore elements 0 and 1 in the array. Sieve of Eratosthenes aw 2 3 5 7 8. 6 19 sieve 7510 11 12 ET 18+ 15 10 17 1 19 201 X prome? No sun Simth , .. 23 PZ 25 ( 29 28 * * 30 31 TE 13 31 SE 37 3 39 40 * X XX X XIX 102683 41 4 44 45 45 47 49 50 X WP ts 53 109 61 16 65 48 09 XX 71 . 73 79 13 83 12 x NX 1X 18 89 X 25 901 97 TO SieveArray x Compile Undo Cut Copy Paste Find... Close Source Code /** * Class SieveArray */ import java.util.*; public class SieveArray { public static void main(String[] args) { final int size = 1000; boolean[] prime = new boolean[size]: // ADD CODE HERE TO CORRECTLY FILL prime ARRAY W display the results for( int i=2; i

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

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

Students also viewed these Databases questions

Question

What are the objectives of Human resource planning ?

Answered: 1 week ago

Question

Explain the process of Human Resource Planning.

Answered: 1 week ago

Question

=+j Describe the various support services delivered by IHR.

Answered: 1 week ago

Question

=+j Explain IHRMs role in global HR research.

Answered: 1 week ago

Question

=+j Describe an effective crisis management program.

Answered: 1 week ago