Java出力100~999間の水仙数

433 ワード

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("
:" + i); } } } }