水仙花数是指其个位、十位和百位3个数的立方和等于这个三位数本身。求所有的水仙花数。(java语言编程)

[复制链接]
查看11 | 回复2 | 2011-9-28 11:11:33 | 显示全部楼层 |阅读模式
public class Main {
public static void main(String[] args) {
int x;
for (x = 100;x <= 999;x++)
{int temp100 = x/100;int temp10 = (x/10)%10;int temp1 = x%10;if(Math.pow(temp100, 3) + Math.pow(temp10, 3) + Math.pow(temp1, 3) == x){
System.out.println(x);}
}
...
回复

使用道具 举报

千问 | 2011-9-28 11:11:33 | 显示全部楼层
int n = 1000;int y1,y2,y3;for(int i=1;i<1000;i++){y1=i/100;y2=i/10%10;y3=i%10;if((y1*y1*y1+y2*y2*y2+y3*y3*y3)==i){System.out.println(i);}...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行