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 編程題目 第三題
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.