首页 > 编程语言 > 详细

算法9:What is the sum of the digits of the number 21000

时间:2020-06-24 17:42:12      阅读:65      评论:0      收藏:0      [点我收藏+]

 

技术分享图片

 

 What is the sum of the digits of the number 21000

 

 

    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 < str_retVal.length(); 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

原文:https://www.cnblogs.com/bors/p/sumDigits.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!