a question that i'm doing is this:
Quote:
Problem 20
n! means n × (n − 1) × ... × 3 × 2 × 1
Find the sum of the digits in the number 100!
the problem with this is that the sum is too big(unless i did something wrong) thus it keeps displaying 0. is there any way to fix that?
code: |
public class Problem20 {
public static void main (String[] args){
int n = 100;
int total = 100;
int sum = 0;
for (int i = 1; i <= 99; i++){
total = total * (n-i);
}
for (int j = 1; j <= total; j++){
sum = sum + j;
}
System.out.println(sum);
}
} |