-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathseivePrimeNumber
More file actions
54 lines (27 loc) · 815 Bytes
/
seivePrimeNumber
File metadata and controls
54 lines (27 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.Arrays;
// Seive algortihm for prime number
public class PrimeNumber{
public static void printPrimeNumber(boolean array []) {
for(int j=0;j<=array.length;j++) {
if(array[j]==true) {
System.out.println("tHIS IS THE PRIME NUMBER:" + j);
}
}
}
public static void seiveErathosis (boolean array [] , int number) {
Arrays.fill(array, true);
array[0]=false;
array[1]= false;
for(int i=2;i<=4;i++){
for(int k=2*i;k<=number;k+=i) {
array[k]= false;
}
}
}
public static void main(String []args){
int number = 17;
boolean array[]= new boolean[number+1];
seiveErathosis(array , number);
printPrimeNumber(array);
}
}