[Java] Java打印出1000以内的所有水仙花数 →→→→→进入此内容的聊天室

来自 , 2021-03-06, 写在 Java, 查看 119 次.
URL http://www.code666.cn/view/8196e8d0
  1. public class exp2{
  2.     public static void main(String args[]){
  3.        int i=0;
  4.        math mymath = new math();
  5.        for(i=100;i<=999;i++)
  6.            if(mymath.shuixianhua(i)==true)
  7.            System.out.println(i);
  8.     }
  9. }
  10. class math
  11. {
  12.     public int f(int x)
  13.     {
  14.        if(x==1 || x==2)
  15.            return 1;
  16.        else
  17.            return f(x-1)+f(x-2);
  18.     }
  19.     public boolean iszhishu(int x)
  20.     {
  21.        for(int i=2;i<=x/2;i++)
  22.            if (x % 2==0 )
  23.               return false;
  24.        return true;
  25.     }
  26.     public boolean shuixianhua(int x)
  27.     {
  28.        int i=0,j=0,k=0;
  29.        i=x / 100;
  30.        j=(x % 100) /10;
  31.        k=x % 10;
  32.        if(x==i*i*i+j*j*j+k*k*k)
  33.           return true;
  34.        else
  35.           return false;
  36.      
  37.     }
  38. }
  39. //java/7282

回复 "Java打印出1000以内的所有水仙花数"

这儿你可以回复上面这条便签

captcha