java蓝桥杯练习 判断水仙花
资源限制
时间限制:1.0s 内存限制:256.0MB
水仙花数
问题描述
判断给定的三位数是否 水仙花 数。所谓 水仙花 数是指其值等于它本身 每位数字立方和的数。例 153 就是一个 水仙花 数。 153=13+53+33
输入格式
一个整数。
输出格式
是水仙花数,输出"YES",否则输出"NO"(不包括引号)
样例输入
123
样例输出
NO
数据规模和约定
一个三位的整数,否则输出"NO"
//java代码
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
if (i < 100 && i > 999)
System.out.println("NO");
int a = i / 100;
int b = i % 100 / 10;
int c = i % 10;
if (a * a * a + b * b * b + c * c * c == i)
System.out.println("YES");
else
System.out.println("NO");
}
}