输出100~999之间的所有水仙花数。若三位数ABC满足ABC=A*A*A+B*B*B+C*C*C,则称其为水仙花数。例如153=1*1*1+5*5*5+3*3*3,所以153是水仙花数。
样例输出:153 370 371 407
下面贴出源码:
package cn.zimo.algorithm;
/*** 水仙花数* @author 子墨* @date 2018年4月26日 下午1:40:54*/
public class Demo08 {public static void main(String[] args) {for(int i=100;i<=999;i++) {int a=i/100;int b=i/10%10;int c=i%10;if(i==(a*a*a+b*b*b+c*c*c)) {System.out.print(i+" ");}}}}