The following is a small Java project given to me in class. The directions seem
ID: 3530361 • Letter: T
Question
The following is a small Java project given to me in class. The directions seem pretty straight forward but it's hard for me to conceptualize it and in turn put it in the form of a code that actually works... Any pointers, sample source codes, useful methods etc. are appreciated.
http://s24.postimage.org/ah4qigcrp/sieve.gif
Implement a method with the following declaration:
Implement a method with the following declaration:
Output for your program: All prime numbers between 1 and 1000000and all even numbers between 4 and 1000000 and the two primenumbers that sum up to it.
Explanation / Answer
// please rate me 5 star first if u like my answer
import java.util.Scanner ;
class Example{
public int size ;
Scanner in = new Scanner(System.in);
size = in.nextInt();
public static void sieve(int[] array){
for(i=1;i<size;i=i+2)
array[i]=0;
for(i=3;i<size;i=i+2){
if(array[i-1]/i==0)
arr[i-1]=0;
}
}
public static void goldbach(int[] array){
for(i=0;i<size;i=i+2){
if(i/2==0)
array[i]=i+4;
else
array[i]= 0 ;
}
}
public static void main(String arg[]){
int arr1[] = new int[size] ;
int arr2[] = new int[size] ;
sieve(arr1);
goldbach(arr2);
for(i=0;i<size;i=i+1)
System.out.print (arr1[i]+ '" ");
for(i=0;i<size;i=i+1)
System.out.print (arr2[i]+ '" ");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.