Java输出100~999之间的水仙花数

package homework;

public class NarcissisticNumber {

	public static void main(String[] args) {
		
		System.out.println("100~999之间的水仙花数:");
		for (int i = 100; i < 999; i++) {
			int unit = i % 10;
			int ten = i / 10 % 10;
			int hundred = i / 100;
			if (unit * unit * unit + ten * ten * ten + hundred * hundred * hundred == i) {
				System.out.println("\n水仙花数:" + i);
			}
		}

	}

}

你可能感兴趣的:(典化成籍-Java)