Skip to content

Commit 18c6ed5

Browse files
add Problem01
1 parent 9271278 commit 18c6ed5

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.examplehub.projecteuler;
2+
3+
public class Problem01 {
4+
5+
public static int solution1(int n) {
6+
int sum = 0;
7+
for (int i = 1; i < n; ++i) {
8+
if (i % 3 == 0 || i % 5 == 0) {
9+
sum += i;
10+
}
11+
}
12+
return sum;
13+
}
14+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.examplehub.projecteuler;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
class Problem01Test {
8+
9+
@Test
10+
void testSolution1() {
11+
12+
assertEquals(0, Problem01.solution1(-100));
13+
assertEquals(0, Problem01.solution1(3));
14+
assertEquals(3, Problem01.solution1(4));
15+
assertEquals(23, Problem01.solution1(10));
16+
assertEquals(233168, Problem01.solution1(1000));
17+
}
18+
}

0 commit comments

Comments
 (0)