看看我这个问题出在哪:public class A_3 {
public static void main(String[] args){
int a =0,b =0,c =0;
if((a>0&&a<10)||(b>0&&b<10)||(c>0&&c<10)){
int math = a*100 + b*10 + c;
int lfhe = a*a*a +b*b*b +c*c*c;
for(math = 100;math<1000;math++){
if(math == lfhe)
System.out.println(math);
}
}
}
}
public static void main(String[] args){
int a =0,b =0,c =0;
if((a>0&&a<10)||(b>0&&b<10)||(c>0&&c<10)){
int math = a*100 + b*10 + c;
int lfhe = a*a*a +b*b*b +c*c*c;
for(math = 100;math<1000;math++){
if(math == lfhe)
System.out.println(math);
}
}
}
}
public static void main(String[] args){
int a = 0,b = 0,c = 0;
System.out.println("水仙花数:");
for(int i=100;i<1000;i++)
{
a = i/100; // 百位
b = i%100/10; // 十位
c = i%100%10; // 个位
if(i==a*a*a+b*b*b+c*c*c)
{
System.out.print(i+"\t");
}
}
}}
{
static int a,b,c,d;
public static void main(String [] args)
{
for(int j=100;j<=999;j++)
{
p(j);
if(Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3)==j)
System.out.println(j);
}
}
public static void p(int i)
{
a = i/100;
d = i%100;
b = d/10;
c = d%10;
}
}
没有将3位数的百位,十位,个位 给 分离出来放到 a,b,c里?
我还是觉得我那样写按道理来说是不应该有问题的。我想知道错误的原因?
a=0,所有a>0&&a<10=false;所以没有结果。
public class A_3 {
public static void main(String[] args){
int a,b,c;
for(a=1;a<=9;a++)//百位不能为0
{
for(b=0;b<=9;b++)
{
for(c=0;c<=9;c++)
{
int math = a*100 + b*10 + c;
int lfhe = a*a*a +b*b*b +c*c*c;
if(math == lfhe)
System.out.println(math);
}
}
} }
}