java判断一个数是不是水仙花数
作者:互联网
// 水仙花数是三位的数字 如:153,370,371,407;
//水仙花数各位、十位、百位的三次方之和等于这个数本身
import java.util.Scanner;
public class test1 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("请输入要判断的数字:");
int n = in.nextInt();
int a = n % 10;
int b = n / 10 % 10;
int c = n / 100;
int num = a*a*a + b*b*b + c*c*c;
if (num == n) {
System.out.println(n + "是水仙花数");
}else {
System.out.println("不是水仙花数");
}
}
}
标签:10,java,Scanner,int,是不是,System,水仙花,out 来源: https://blog.csdn.net/qq_51369065/article/details/119283285