资源限制
时间限制:1.0s 内存限制:256.0MB
问题描述
求出所有的“水仙花数”。所谓的“水仙花数”,是指一个3位数,其各位数字的立方和等于该数本身。
输入格式
程序使用for循环遍历所有三位数整数,不需要手动输入
输出格式
遇到水仙花数输出
样例输入
无输入
样例输出
例:
153
370
371
407
数据规模和约定
输入数据中每一个数的范围。
例:100~999
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
for(int x=100;x<1000;x++) {
int a=x/100;
int b=x/10%10;
int c=x%10;
if((int)(Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3))==x)
System.out.println(x);
}
}
}