-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem056.java
More file actions
35 lines (31 loc) · 999 Bytes
/
problem056.java
File metadata and controls
35 lines (31 loc) · 999 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
29
30
31
32
33
34
35
package project_beuler;
public class problem056 {
// A googol (10^100) is a massive number: one followed by one-hundred zeros;
// 100^100 is almost unimaginably large: one followed by two-hundred zeros.
// Despite their size, the sum of the digits in each number is only 1.
//
// Considering natural numbers of the form, ab, where a,
// b < 100, what is the maximum digital sum?
public static void main(String[] args) {
// TODO Auto-generated method stub
int max = 0;
for(int a = 100; a > 0; a--)
if(a% 10 != 0)
for(int b = 100; b > 0; b--) {
String[] power = new String[b];
for(int i = 0; i < power.length; i++)
power[i] = a+"";
String value = Interface.multString(power);
if( value.length() < max/10 )
break;
max = Math.max( max, digitSum(value) );
}
System.out.println(max);
}
public static int digitSum(String number) {
int i = 0;
for(int x = 0; x < number.length(); x++)
i += Integer.parseInt(number.charAt(x)+"");
return i;
}
}