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

     1 //题目:打印出所有的"水仙花数(narcissus number)",所谓"水仙花数"是指一个三位数,
     2 //其各位数字立方和等于该数本身。例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。
     3 public class lianxi {
     4  //1.100-999  2.各个数字分离出来,需要求余%,和整除/     3.用立方的函数,不用也行Math.pow(a,3)
     5 ////256 2=256/100    5=256%100/10  6=256%100%10
     6 static int a,b,c;
     7 public static void main(String[] args) {
     8     
     9     
    10     for(int i=100;i<1000;i++) {
    11         a=i/100;
    12         b=(i%100)/10;
    13         c=(i%100)%10;
    14         if(Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3)==i)
    15             System.out.print(i+" ");
    16         
    17     }
    18 }
    19 }
    153 370 371 407 
  • 相关阅读:
    LeetCode 55
    LeetCode 337
    LeetCode 287
    LeetCode 274
    LeetCode 278
    LeetCode 264
    LeetCode 189
    LeetCode 206
    LeetCode 142
    LeetCode 88
  • 原文地址:https://www.cnblogs.com/P201421420035/p/8664578.html
Copyright © 2011-2022 走看看