zoukankan      html  css  js  c++  java
  • Java经典编程题50道之三

    打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。

    public class Example03 {
        public static void main(String[] args) {
            s();
        }

        public static void s() {
            int count = 0;
            int a, b, c;
            for (int i = 100; i < 1000; i++) {
                a = i / 100;
                b = i % 100 / 10;
                c = i % 10;
                if (i == (a * a * a + b * b * b + c * c * c)) {
                    count++;
                    System.out.print(i + " ");
                    if (count % 10 == 0) {
                        System.out.println();
                    }
                }
            }
            System.out.println(" 共有" + count + "个"水仙花数"。");
        }
    }

  • 相关阅读:
    poj1182 食物链
    poj1611 The Suspects
    poj3436 Computer Factory
    (转) GPG入门教程
    cronolog安装配置
    RHCA-436-4 rhcs conga
    pxe引导gparted live万能分区
    linux下拔号pptp
    GNU parted简略用法
    hostapd故障解决(1.1,2.0,2.2)
  • 原文地址:https://www.cnblogs.com/qubo520/p/6924479.html
Copyright © 2011-2022 走看看