打出三位数的所有水仙花数

/**
 * 题目:打印出所有的 "水仙花数 ",所谓 "水仙花数 "是指一个三位数,
 * 其各位数字立方和等于该数本身。例如:153是一个 "水仙花
 * 数 ",因为153=1的三次方+5的三次方+3的三次方
 */
public class 水仙花数 {

	public static void main(String[] args) {
		for (int i = 100; i < 1000; i++) {
			int first = i/100;
			int secode= i/10%10;
			int thrid = i%10;
			if (first*first*first+secode*secode*secode+thrid*thrid*thrid == i) {
				System.out.println(i+"是水仙花数");
			}
		}
	}
}

猜你喜欢

转载自blog.csdn.net/BlackPlus28/article/details/88230365