我除了遍历找不出第二种方法

解决方案 »

  1.   

    只有遍历全部...
    public class ShuiXianHuaDemo{
    public static void main(String args[]){
    for(int i = 100 ; i < 999 ; i++){
    int geWei,shiWei,baiWei;
    baiWei = i /100;
    shiWei = i/10%10;
    geWei = i%100%10;
    //System.out.println(baiWei+" "+shiWei+" "+geWei);
    //if(i==geWei*geWei*geWei+shiWei*shiWei*shiWei+baiWei*baiWei*baiWei){
    if(i == Math.pow(geWei,3) + Math.pow(shiWei,3) + Math.pow(baiWei,3)){
    //注:求N次方可以用java.lang.Math.pow(a, b);
    System.out.println(i);
    }
    }
    }
    }