ZZULIOJ 1027: 判断水仙花数

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014543872/article/details/83514507

题目描述

春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的: 
“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=13+53+33。 
 现在要求输入一个三位数,判断该数是否是水仙花数,如果是,输出“yes”,否则输出“no”  

输入

输入一个三位的正整数。 

输出

输出“yes”或“no”。 

样例输入

153

样例输出

yes
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);

		int num = input.nextInt();

		int a = num / 100;
		int b = num / 10 % 10;
		int c = num % 10 % 10;

		if (num == a * a * a +b * b * b + c * c * c) {
			System.out.println("yes");
		} else {
			System.out.println("no");
		}

	}
}

猜你喜欢

转载自blog.csdn.net/u014543872/article/details/83514507