Skip to content

Commit f582ee6

Browse files
committed
fix: remove trailing spaces
1 parent 1564aab commit f582ee6

2 files changed

Lines changed: 22 additions & 22 deletions

File tree

src/main/java/com/thealgorithms/maths/SieveOfEratosthenes.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,30 @@
66
/**
77
* Sieve of Eratosthenes Algorithm
88
* An efficient algorithm to find all prime numbers up to a given limit.
9-
*
9+
*
1010
* Algorithm:
1111
* 1. Create a boolean array of size n+1, initially all true
1212
* 2. Mark 0 and 1 as not prime
1313
* 3. For each number i from 2 to sqrt(n):
1414
* - If i is still marked as prime
1515
* - Mark all multiples of i (starting from i²) as not prime
1616
* 4. Collect all numbers still marked as prime
17-
*
17+
*
1818
* Time Complexity: O(n log log n)
1919
* Space Complexity: O(n)
20-
*
20+
*
2121
* @author Navadeep0007
2222
* @see <a href="https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes">Sieve of Eratosthenes</a>
2323
*/
2424
public final class SieveOfEratosthenes {
25-
25+
2626
private SieveOfEratosthenes() {
2727
// Utility class, prevent instantiation
2828
}
29-
29+
3030
/**
3131
* Finds all prime numbers up to n using the Sieve of Eratosthenes algorithm
32-
*
32+
*
3333
* @param n the upper limit (inclusive)
3434
* @return a list of all prime numbers from 2 to n
3535
* @throws IllegalArgumentException if n is negative
@@ -38,17 +38,17 @@ public static List<Integer> findPrimes(int n) {
3838
if (n < 0) {
3939
throw new IllegalArgumentException("Input must be non-negative");
4040
}
41-
41+
4242
if (n < 2) {
4343
return new ArrayList<>();
4444
}
45-
45+
4646
// Create boolean array, initially all true
4747
boolean[] isPrime = new boolean[n + 1];
4848
for (int i = 2; i <= n; i++) {
4949
isPrime[i] = true;
5050
}
51-
51+
5252
// Sieve process
5353
for (int i = 2; i * i <= n; i++) {
5454
if (isPrime[i]) {
@@ -58,21 +58,21 @@ public static List<Integer> findPrimes(int n) {
5858
}
5959
}
6060
}
61-
61+
6262
// Collect all prime numbers
6363
List<Integer> primes = new ArrayList<>();
6464
for (int i = 2; i <= n; i++) {
6565
if (isPrime[i]) {
6666
primes.add(i);
6767
}
6868
}
69-
69+
7070
return primes;
7171
}
72-
72+
7373
/**
7474
* Counts the number of prime numbers up to n
75-
*
75+
*
7676
* @param n the upper limit (inclusive)
7777
* @return count of prime numbers from 2 to n
7878
*/

src/test/java/com/thealgorithms/maths/SieveOfEratosthenesTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,52 @@
1010

1111
/**
1212
* Test cases for Sieve of Eratosthenes algorithm
13-
*
13+
*
1414
* @author Navadeep0007
1515
*/
1616
class SieveOfEratosthenesTest {
17-
17+
1818
@Test
1919
void testPrimesUpTo10() {
2020
List<Integer> expected = Arrays.asList(2, 3, 5, 7);
2121
assertEquals(expected, SieveOfEratosthenes.findPrimes(10));
2222
}
23-
23+
2424
@Test
2525
void testPrimesUpTo30() {
2626
List<Integer> expected = Arrays.asList(2, 3, 5, 7, 11, 13, 17, 19, 23, 29);
2727
assertEquals(expected, SieveOfEratosthenes.findPrimes(30));
2828
}
29-
29+
3030
@Test
3131
void testPrimesUpTo2() {
3232
List<Integer> expected = Arrays.asList(2);
3333
assertEquals(expected, SieveOfEratosthenes.findPrimes(2));
3434
}
35-
35+
3636
@Test
3737
void testPrimesUpTo1() {
3838
assertTrue(SieveOfEratosthenes.findPrimes(1).isEmpty());
3939
}
40-
40+
4141
@Test
4242
void testPrimesUpTo0() {
4343
assertTrue(SieveOfEratosthenes.findPrimes(0).isEmpty());
4444
}
45-
45+
4646
@Test
4747
void testNegativeInput() {
4848
assertThrows(IllegalArgumentException.class, () -> {
4949
SieveOfEratosthenes.findPrimes(-1);
5050
});
5151
}
52-
52+
5353
@Test
5454
void testCountPrimes() {
5555
assertEquals(4, SieveOfEratosthenes.countPrimes(10));
5656
assertEquals(25, SieveOfEratosthenes.countPrimes(100));
5757
}
58-
58+
5959
@Test
6060
void testLargeNumber() {
6161
List<Integer> primes = SieveOfEratosthenes.findPrimes(1000);

0 commit comments

Comments
 (0)