MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / sieveOfEratosthenes

Method sieveOfEratosthenes

Programs/seive.java:4–27  ·  view source on GitHub ↗
(int n)

Source from the content-addressed store, hash-verified

2class SieveOfEratosthenes
3{
4 void sieveOfEratosthenes(int n)
5 {
6 boolean prime[] = new boolean[n+1];
7 for(int i=0;i<=n;i++)
8 prime[i] = true;
9
10 for(int p = 2; p*p <=n; p++)
11 {
12
13 if(prime[p] == true)
14 {
15
16 for(int i = p*p; i <= n; i += p)
17 prime[i] = false;
18 }
19 }
20
21
22 for(int i = 2; i <= n; i++)
23 {
24 if(prime[i] == true)
25 System.out.print(i + " ");
26 }
27 }
28
29 public static void main(String args[])
30 {

Callers 1

mainMethod · 0.95

Calls 1

printMethod · 0.80

Tested by

no test coverage detected