2
15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 21000?
/** * I don't have a good idea. * * I just calculate the result of 2 to the 1000th power. * * Then get the summary of each digits. * */ public static int twoPower(int index) { BigDecimal result = BigDecimal.ONE; BigDecimal two = BigDecimal.ONE.add(BigDecimal.ONE); for (int i = 0; i < index; i++) { result = result.multiply(two); } String s = result.toString(); int sum = 0; System.out.print(s); for (char c : s.toCharArray()) { sum += (c - '0'); } return sum; }