public class Main {
public static void main(String[] args) {
int x;
for (x = 100;x <= 999;x++)
{
int temp100 = x/100;
int temp10 = (x/10)%10;
int temp1 = x%10;
if(Math.pow(temp100, 3) + Math.pow(temp10, 3) + Math.pow(temp1, 3) == x)
{
System.out.println(x);
}
}
}
}
上面就是代码了!纯手工打。输出结果为:
153
370
371
407
int n = 1000;
int y1,y2,y3;
for(int i=1;i<1000;i++){
y1=i/100;
y2=i/10%10;
y3=i%10;
if((y1*y1*y1+y2*y2*y2+y3*y3*y3)==i){
System.out.println(i);
}
}