Skip to content

Commit 874144d

Browse files
add problem 20
1 parent b82d18b commit 874144d

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/main/java/com/examplehub/maths/SumOfDigits.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class SumOfDigits {
88
* @param number the number.
99
* @return the sum of digits.
1010
*/
11-
public static int sumOfDigits(int number) {
11+
public static int sumOfDigits(long number) {
1212
number = Math.abs(number);
1313
int sum = 0;
1414
while (number != 0) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.examplehub.projecteuler;
2+
3+
import com.examplehub.maths.Factorial;
4+
import com.examplehub.maths.SumOfDigits;
5+
6+
public class Problem20 {
7+
public static int solution1(int number) {
8+
return SumOfDigits.sumOfDigits(Factorial.factorial(number));
9+
}
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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 Problem20Test {
8+
9+
@Test
10+
void test() {
11+
assertEquals(27, Problem20.solution1(10));
12+
}
13+
}

0 commit comments

Comments
 (0)