Help me with this program anybody

Page 1 of 1

1 Replies - 1828 Views - Last Post: 03 October 2008 - 01:10 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=65989&amp;s=c0ddf1c9576503450e890bb813960ad0&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 deven1974

Reputation: 0
• Posts: 53
• Joined: 03-October 08

Help me with this program anybody

Posted 03 October 2008 - 12:36 PM

The Sieve of Eratosthenes and Goldbach's Conjecture
Implement the Sieve of Eratosthenes 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.

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 should output for all primes 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, divisioni, or modulus when determining if
a number is prime. It also means that the second method must find
two primes efficiently.

Output 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.

DO NOT provide output or a session record for this project!

Hello can anybody help with this program
So far I have this program do little bit, but I need to get help with first and second part of this program.

```import java.util.Scanner;

public class SievePr
{
public static void main(String[] args)
{
int prime;
Scanner scan = new Scanner (System.in);
System.out.println ("Enter the prime number: ");
prime = scan.nextInt();

int arr[] = new int[prime];
Sieve(arr);
}

public static void Sieve(int[] array)
{
int prime = arr.length;
for (int a = 1; a <= arr.length; a++)
if (arr[a] == 1)

System.out.print (a);

}

}

```

This post has been edited by deven1974: 03 October 2008 - 12:38 PM

Is This A Good Question/Topic? 0

Replies To: Help me with this program anybody

#2 Gloin

• Expert Schmexpert...

Reputation: 235
• Posts: 4,489
• Joined: 04-August 08

Re: Help me with this program anybody

Posted 03 October 2008 - 01:10 PM