三位數的 Armstrong 數

Fundamental Syntax
回覆文章
頭像
davidlan
文章: 167
註冊時間: 2014年 7月 28日, 09:09

三位數的 Armstrong 數

文章 davidlan » 2014年 8月 11日, 12:09

public class Exercise3_2 {
public static void main(String[] args) {
for(int i = 100; i < 1000; i++) {
if (Math.pow(i / 100, 3) + Math.pow((i % 100) / 10, 3) + Math.pow(i % 10, 3) == i) {
System.out.println(Math.pow(i / 100, 3));
System.out.println(Math.pow(i % 100, 3));
System.out.println(Math.pow(i % 10, 3));
System.out.printf("%d %n%n", i);
}
}
}
}
--------8<--------8<--------8<--------8<----
1.0
125.0
27.0
153

27.0
343.0
0.0
370

27.0
343.0
1.0
371

64.0
0.0
343.0
407
-------->8-------->8-------->8-------->8----

回覆文章