package com.practice.demo01;
public class Demo06 {
public static void main(String[] args) {
//输出所有的水仙花数,所谓水仙花数是指一个数3位数,其每位数字立方和等于其本身,如153 = 1*1*1 + 3*3*3 + 5*5*5(很经典的题目)
for (int i = 100; i < 1000; i++) {//先for循环输出100~1000之间的3位数
int a = i/100%10;//取百位数
int b = i/10%10;//取十位数
int c = i%10;//取个位数
if (i==a*a*a + b*b*b + c*c*c){
System.out.println(i);
}
}
}
}
Java输出水仙花数
最新推荐文章于 2024-08-18 21:12:37 发布