写的是一个1到1000的水仙花数,也就是象这样的数:153=1的立方+5的立方+3的立方等于这个数 ,大哥门帮我看看 哪错了我急呀
package pck;
public class Test
{
public static void main(String[] args){
int one,two,three;
boolean b=true;
for(int i=0;i<1000;i++){
one=i%10;
two=(i%100-one)/10;
three=(i-one-two*10)/100;
if((one*one*one+two*two*two+three*three*three)!=i)
System.out.println(i);
}
}
}
package pck;
public class Test
{
public static void main(String[] args){
int one,two,three;
boolean b=true;
for(int i=0;i<1000;i++){
one=i%10;
two=(i%100-one)/10;
three=(i-one-two*10)/100;
if((one*one*one+two*two*two+three*three*three)!=i)
System.out.println(i);
}
}
}
1 所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。
所以你的程序I应该从100开始
2 if((one*one*one+two*two*two+three*three*three)!=i) 逻辑错误,
应该是if((one*one*one+two*two*two+three*three*three)==i)
{
public static void main(String[] args){
int one,two,three;
boolean b=true;
for(int i=100;i<1000;i++){
one=i%10;
two=(i%100-one)/10;
three=(i-one-two*10)/100;
if(i==one*one*one+two*two*two+three*three*three)
System.out.println(i);
}
}
}
ok 的代码!!!
呵呵...
one=i/100; //百位
two=i%100/10; //十位
three=i%10; //个位
public class Test
{
public static void main(String[] args){
int one,two,three;
boolean b=true;
for(int i=100;i<1000;i++){
one=i%10;
two=(i%100-one)/10;
three=(i-one-two*10)/100;
if(i==one*one*one+two*two*two+three*three*three)
System.out.println(i);
}
}
}
one=i%10;
two=(i%100-one)/10;
three=(i-one-two*10)/100;
好麻烦啊
这样比较容易理解
one=i/100;
two=i%100/10;
three=i%10;
还是个迷糊
b是什么东东?