水仙花数

public class Test6 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个数:");
        int num = scan.nextInt();
        int number = number(num);
        if (num == number) {
            System.out.println(num + "是水仙花数");
        }else{
            System.out.println(num+"不是水仙花数");
        }
    }

    public static int number(int num) {
        int sum = 0;
        int bit = 0;
        int temp;
        for (int i = num; i != 0; i = i / 10) {
            bit++;
        }
        for (int i = num; i > 0; i = i / 10) {
            int shu = i % 10;
            temp = shu;
            for (int j = 1; j < bit; j++) {
                temp *= shu;
            }
            sum += temp;
        }
        return sum;
    }
}

给TA打赏
共{{data.count}}人
人已打赏
知识碎片

mysql-(单元函数/日期时间类型)

2022-2-24 20:47:18

知识碎片

JDBC连接数据库

2022-3-9 20:04:42

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧