编程实现判断一个整数是否为“水仙花数”。所谓“水仙花数”是指一个三位的整数,
答案:2 悬赏:60
解决时间 2021-04-28 11:34
- 提问者网友:你在我眼中是最帅
- 2021-04-27 14:44
编程实现判断一个整数是否为“水仙花数”。所谓“水仙花数”是指一个三位的整数,
最佳答案
- 二级知识专家网友:温柔刺客
- 2021-04-27 16:07
For[r = 100, r <= 999, r++,
If[r != (IntegerPart[
r/100])^3 + (IntegerPart[(r - 100*(IntegerPart[r/100]))/
10])^3 + (IntegerPart[
r - IntegerPart[r/100]*100 -
IntegerPart[(r - 100*(IntegerPart[r/100]))/10]*10])^3,
Continue[]]; Print[r]]
153
370
371
407
我这是Wolfram Mathematica程序,其他的你可以网上看看
If[r != (IntegerPart[
r/100])^3 + (IntegerPart[(r - 100*(IntegerPart[r/100]))/
10])^3 + (IntegerPart[
r - IntegerPart[r/100]*100 -
IntegerPart[(r - 100*(IntegerPart[r/100]))/10]*10])^3,
Continue[]]; Print[r]]
153
370
371
407
我这是Wolfram Mathematica程序,其他的你可以网上看看
全部回答
- 1楼网友:有钳、任性
- 2021-04-27 16:13
public class shuixianhuashu
{
public boolean ifshuixianhuashu(int m)
{
int gewei,shiwei,baiwei;
baiwei=m/100;
shiwei=(m-baiwei*100)/10;
gewei=m-baiwei*100-shiwei*10;
if(m==gewei*gewei*gewei+shiwei*shiwei*shiwei+baiwei*baiwei*baiwei)
{
return true;
}
else
{
return false;
}
}
public static void main(string[] args) {
boolean b = new shuixianhuashu().ifshuixianhuashu(153); //此处的153可以更改为你需要判断的整数
if(b==true)
{
system.out.println("这个数是水仙花数");
}
else
{
system.out.println("这个数不是水仙花数");
}
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息