算法9:What is the sum of the digits of the number 21000
2021-05-06 16:27
标签:har ima 图片 ber number code git stat char What is the sum of the digits of the number 21000 结果 算法9:What is the sum of the digits of the number 21000 标签:har ima 图片 ber number code git stat char 原文地址:https://www.cnblogs.com/bors/p/sumDigits.html public static int sumDigits(int n) {
int int_retVal = 0;
int int_pow = (int) Math.pow(2, n);
String str_retVal = String.valueOf(int_pow);
for (int i = 0; i ) {
int_retVal += Integer.parseInt(String.valueOf(str_retVal.charAt(i)));
}
System.out.println(int_pow + ", " + int_retVal);
return int_retVal;
}
public static void main(String[] args) {
sumDigits(1000);
}
2147483647, 46
文章标题:算法9:What is the sum of the digits of the number 21000
文章链接:http://soscw.com/essay/83285.html