Here you can find the source of sumOfDigits(BigInteger n)
public static int sumOfDigits(BigInteger n)
//package com.java2s; //License from project: Open Source License import java.math.BigInteger; public class Main { public static int sumOfDigits(long n) { int sum = 0; while (n != 0) { sum += n % 10;/*from ww w. j av a 2s . c o m*/ n /= 10; } return sum; } public static int sumOfDigits(BigInteger n) { int sum = 0; while (!n.equals(BigInteger.ZERO)) { sum += n.remainder(BigInteger.TEN).intValue(); n = n.divide(BigInteger.TEN); } return sum; } }