Skip to content
Snippets Groups Projects
Commit 73e4082d authored by Antony Nixen Raj's avatar Antony Nixen Raj
Browse files

Sieve Of Eratosthenes

parent 86e5d28f
Branches main
No related tags found
No related merge requests found
package NumberSystem;
import java.util.ArrayList;
public class SieveOfEratosthenes {
static ArrayList<Integer> sieveOfEratosthenes(int n) {
ArrayList<Integer> arr= new ArrayList<>();
for(int i=2;i<=n;i++){
if(isPrime(i))
arr.add(i);
}
return arr;
}
static boolean isPrime(int n){
for(int i=2;i<n;i++){
if(n%i==0)
return false;
}
return true;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment