From 73e4082dcf691624a49258f4522b86b540724500 Mon Sep 17 00:00:00 2001 From: Antonynixenraj <antonynixen@gmail.com> Date: Sat, 22 Mar 2025 11:03:10 +0530 Subject: [PATCH] Sieve Of Eratosthenes --- NumberSystem/SieveOfEratosthenes.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 NumberSystem/SieveOfEratosthenes.java diff --git a/NumberSystem/SieveOfEratosthenes.java b/NumberSystem/SieveOfEratosthenes.java new file mode 100644 index 0000000..ff207a6 --- /dev/null +++ b/NumberSystem/SieveOfEratosthenes.java @@ -0,0 +1,24 @@ +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; + } +} -- GitLab