ZZULIOJ 1027: 判斷水仙花數
阿新 • • 發佈:2018-11-05
題目描述
春天是鮮花的季節,水仙花就是其中最迷人的代表,數學上有個水仙花數,他是這樣定義的:
“水仙花數”是指一個三位數,它的各位數字的立方和等於其本身,比如: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"); } } }