forked from Tecmax/JavaAndroidPractise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp020.java
More file actions
28 lines (22 loc) · 644 Bytes
/
p020.java
File metadata and controls
28 lines (22 loc) · 644 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
* Solution to Project Euler problem 20
* Copyright (c) Project Nayuki. All rights reserved.
*
* https://www.nayuki.io/page/project-euler-solutions
* https://github.com/nayuki/Project-Euler-solutions
*/
public final class p020 implements EulerSolution {
public static void main(String[] args) {
System.out.println(new p020().run());
}
/*
* We do a straightforward product with help from Java's BigInteger type.
*/
public String run() {
String temp = Library.factorial(100).toString();
int sum = 0;
for (int i = 0; i < temp.length(); i++)
sum += temp.charAt(i) - '0';
return Integer.toString(sum);
}
}