Find the sum of the digits in the number 100! (My while loop would not stop)

I've been trying to solve [Problem 20](https://projecteuler.net/problem=20) in Project Euler: > n! means n (n 1) ... 3 * 2 * 1 For example, 10! = 10 * 9 ... 3 * 2 * 1 = 3628800, and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27. Find the sum of the digits in the number 100! This is what I came up with so far. I already got the correct answer (which was 648) with this code, but I got a bit OC, because my code is an infinite loop. After the result became 0 inside the while loop, it just wouldn't stop. Can anybody help me fix this? public static BigInteger problem20(int max){ BigInteger sum = BigInteger.valueOf(0); BigInteger result = BigInteger.valueOf(1); BigInteger currentNum = BigInteger.valueOf(0); for(long i = 1; i

以上就是Find the sum of the digits in the number 100! (My while loop would not stop)的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏