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 + "个"水仙花数"。");
        }
    }

  • 相关阅读:
    111111
    国际化(提取代码中文)
    分库操作(无事务)
    Nignx(四)location语法详解
    Nginx项目笔记
    SAX:进行XML解析
    流处理PDF、Base64
    JAVA8:stream流
    JPA一对多,多对一映射
    有关技术站点
  • 原文地址:https://www.cnblogs.com/qubo520/p/6924479.html
Copyright © 2011-2022 走看看