判断一个整数是否是水仙花数,所谓水仙花数是指一个3位数,其余各位上数字立方和等于其本身
如:153 = 111 + 333 + 555
Scanner myScanner = new Scanner(System.in); System.out.println("请输入一个三位数字:"); int num = myScanner.nextInt(); int n1 = num / 100; int n2 = num % 100 / 10; int n3 = num % 10; if(num == n1*n1*n1 + n2*n2*n2 + n3*n3*n3){ System.out.println(num + "是一个水仙花数"); } else { System.out.println(num + "不是一个水仙花数"); }