Print out all of the "Narcissus prime" with Java
"Narcissus prime number" refers to a three-digit, digit which is equal to the number of cubic and itself.
public class Demo {
public static void main(String[] args) {
int baiwei,shiwei,gewei;
System.out.println("水仙素数为:");
for(int i=100;i<1000;i++) {
baiwei=i/100; //分解获得百位数
shiwei=i/10%10; //分解获得十位数
gewei=i%10; //分解获得个位数
if((baiwei*baiwei*baiwei)+(shiwei*shiwei*shiwei)+(gewei*gewei*gewei)==i) {
System.out.print(i+" ");
}
}
}
}
The results are as follows