水仙花代码

    //求0~999水仙花数并输出
    private static void Narnumber() {
        int i,j,k,num;
        System.out.println("0~999水仙花数为:");
        for (i=0;i <= 9;i++){
            for (j=0; j <= 9;j++){
                for (k=0;k <= 9;k++){
                    num = (i*100) + (j*10) + k;
                    if (Math.pow(i,3) + Math.pow(j,3) + Math.pow(k,3) == num && num >= 100){
                        System.out.print(num + "\t");
                    }
                }
            }
        }
    }

 

posted @ 2022-05-13 17:14  xiaoyongdata  阅读(608)  评论(0编辑  收藏  举报