- 打印水仙花数
- 统计水仙花数
- int a , b , c , sum , num = 0;
- for (int i = 100;i <= 999 ;i++ ) {
- a = i / 100;
- b = (i - a * 100) / 10;
- c = i % 10;
- sum = a * a * a + b * b * b + c * c * c;
- if (sum == i) {
- System.out.println("水仙花数" + i);
- num++;
- }
- }
- System.out.println("水仙花数个数为" + num);
复制代码 |
|