解法:复杂度高
public class Armstrong {
public void Find_Armstrong(){
for(int a = 1; a < 10; a++){
for(int b = 0; b < 10; b++){
for(int c = 0; c <10; c++){
int sum = a * 100 + b * 10 + c;
if((Math.pow(a,3) + Math.pow(b,3) + Math.pow(c,3)) == sum){
System.out.printf("a=%d b=%d c=%d abc=%d",a,b,c,sum);
System.out.println();
}
}
}
}
}
public static void main(String[] args) {
Armstrong armstrong = new Armstrong();
armstrong.Find_Armstrong();
}
}
测试:
153
370
371
407