/**
输入一个三位数判断是不是水仙花数 水仙花数是指一个三位数的各位的立方和等于该数本身。
*/
import java.util.Scanner;
public class TestWork {
public static void main(String[] args) {
System.out.println("请输入一个三位数");
Scanner sc = new Scanner(System.in);
if (sc.hasNextInt()) {
int num = sc.nextInt();
if (num > 99 && num < 1000) {
int a = num / 100;// 百
int b = num / 10 % 10;// 十
int c = num % 10;// 个
int result = (int) Math.pow(a, 3) + (int) Math.pow(b, 3) + (int) Math.pow(c, 3);
if (result == num) {
System.out.println(num + "是水仙花数");
} else {
System.out.println(num + "不是水仙花数");
}
} else {
System.out.println("请输入一个三位数");
}
} else {
System.out.println("请输入正整数");
}
}
}
/**
找出100-999之间所有的水仙花数
*/
public class TestWork {
public static void main(String[] args) {
int Narcount=0;//计数
for (int i = 100; i <= 999; i++) {
int a = i / 100;// 百
int b = i / 10 % 10;// 十
int c = i % 10;// 个
int result = (int) Math.pow(a, 3) + (int) Math.pow(b, 3) + (int) Math.pow(c, 3);
if (result == i) {
Narcount++;
System.out.print(i+"\t");
if(Narcount%5==0){
System.out.println();
}
}
}
}
}