Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement the Sieve of Eratosthenes in Java using Eclipse and use it to find all prime numbers less than or equal to one million. Use

Implement the Sieve of Eratosthenes in Java using Eclipse and use it to find all prime numbers less than or equal to one million. Use the result to prove Goldbach's Conjecture for all even integers between four and one million, inclusive.

image text in transcribed

Implement a method with the following declaration: public static void sieve(int [] array);

This function takes an integer array as its argument. The array should be initialized to the values 1 through 1000000. The function modifies the array so that only the prime numbers remain; all other values are zeroed out. This function must be written to accept an integer array of any size. You must output for all prime numbers between 1 and 1000000, but when I test your function it may be on an array of a different size.

Implement a method with the following declaration: public static void goldbach(int [] array);

This function takes the same argument as the previous method and displays each even integer between 4 and 1000000 with two prime numbers that add to it.

The goal here is to provide an efficient implementation. This means no multiplication, division, or modulus when determining if a number is prime. It also means that the second method must find two primes efficiently.

Outputs for your program: All prime numbers between 1 and 1000000 and all even numbers between 4 and 1000000 and the two prime numbers that sum up to it. Use command line arguments! Please check my code since I have been getting an error message and please fix or make changes to the code. If you can also explain the steps of each part of the code, that would be better. Including screenshots of the code.

import java.math.BigInteger;

public class GoldbachsConjecture { public static void main(String[] args) { int n=Integer.parseInt(args[0]); int array[]=new int[n]; //The array should be initialized to the values 1 through 1000000. for(int i=0;i=2) { number-=2; } if(number==0) result=true; return result; } //to find the two prime numbers that make up an even number private static void sumOfPrime(int[] array, int number, int i) { for(int j=0;j OOXOXOXXX Prime numbers 13 17 19 23) 29 11 13 17 19 .XXXXX><>

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