package com.liuhuan.test;
public class fun03 {
/*
* 题目:打印出所有的 "水仙花数 ",
* 所谓 "水仙花数 "是指一个三位数,其各位数字立方和等于该数本身。
* 例如:153是一个 "水仙花数 ",因为153=1的三次方+5的三次方+3的三次方。
*/
public boolean Isshuixianhua(int i)//i是100-999之间的数字
{
int Ge=0,Shi=0,Bai=0;
Bai=i/100;
Shi=i%100/10;
Ge=i%10;
if(Math.pow(Bai, 3)+Math.pow(Shi, 3)+Math.pow(Ge, 3)==i)
return true;
return false;
}
public static void main(String[] args) {
fun03 testfun=new fun03();
for(int i=100;i<1000;i++){
if(testfun.Isshuixianhua(i)==true){
System.out.print(i+",");
}
}
}
}
Java 编程题目 第三题
最新推荐文章于 2022-11-14 13:55:36 发布