zoukankan      html  css  js  c++  java
  • Java 水仙花数

    小小练习大神掠过吧

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

     1 public static void main(String[] args) {
     2         for(int i=100;i<1000;i++){
     3             if(value(i)){
     4                 System.out.println("i ="+i);
     5             }
     6         }
     7 
     8     }
     9     private static boolean value(int i) {
    10         boolean temp=false;
    11         int b=i/100;
    12         int s=i%100/10;
    13         int g=i%10;
    14         int sum=(int) (Math.pow(b, 3)+Math.pow(s, 3)+Math.pow(g, 3));
    15         if(sum==i){
    16             temp=true;
    17         }
    18         return temp;
    19 
    20     }
  • 相关阅读:
    Day 38
    Day 37
    Day 36
    Day 35
    Day 34
    Day 33
    Day 32
    Day 31
    Day 30
    华为CE6180高级ACL配置
  • 原文地址:https://www.cnblogs.com/bequt/p/5158698.html
Copyright © 2011-2022 走看看