您的位置 首页 编程语言

cube-powerful

A number n>0 is called cube-powerful if it is equal to the sum of the cubes of its digits. Write a function named isCubePowerful that returns 1 if its argument is cube-powerful;
otherwise it returns 0.
The function prototype is
int isCubePowerful(int n);
Hint: use modulo 10 arithmetic to get the digits of the number.

 

 

java代码实现

package com.zzy;

/**
 * 更多请关注: http://huamaodashu.com
 * Created by huamaodashu on 31/07/2018.
 */
public class CubePowerful {
    public static void main(String[] args) {

        System.out.println(isCubePowerful(-81));

    }

    public static int isCubePowerful(int n){

        if(n<=0){
            return 0;
        }

        int tmp = n;
        int sum = 0;
        while (n != 0){
            sum = sum+(int) ( Math.pow((double) (n % 10), 3));
            System.out.println("sum="+sum);
            n=n/10;
        }

        if(sum == tmp){
            return 1;
        }else {
            return 0;
        }
    }
}

猫叔总结了 适合新手操作的副业 《淘宝虚拟产品月入2万的 6个 细分类目》的电子书 仅供参考

如果你对虚拟产品比较感兴趣,可以点击:

淘宝卖什么虚拟产品赚钱(月入2万+)

hadoopall

关于花猫大叔短视频创业 作者: hadoopall

热门文章

发表评论

电子邮件地址不会被公开。