java打印水仙花数

import java.util.Scanner;

public class Narcissistic{//水仙花数
	public static void main(String[] args){
		Scanner in =new Scanner(System.in);
		int x=0;
		for(x=100;x<=999;x++){
			if(x==(x/100)*(x/100)*(x/100)+((x%100)/10)*((x%100)/10)*((x%100)/10)+((x%100)%10)*((x%100)%10)*((x%100)%10)){
				System.out.println(x);
				
			}
		}
	}
		
			
}

你可能感兴趣的:(java基础练习小程序)