java经典问题

//水仙花数
int a=0;
for(int g=0;g<10;g++)//穷举个位数
{
for(int s=0;s<10;s++)//穷举十位
{
for(int b=1;b<10;b++)//穷举个位
{
a=g+s*10+b*100;
if(g*g*g+s*s*s+b*b*b==a)
{
System.out.println("a="+a);
}
}
}
}
//百钱白鸡
int sum=100;
for(int g=0;g<20;g++)
{
for(int m=0;m<33;m++)
{
for(int c = 0;c<100;c+=3)
{
if(sum==(g+m+c)&&sum==(5*g+3*m+c/3))
{
System.out.println(" g = "+g+" m = "+m+" c = "+c);
}
}
}
}

//百马百担
int s=100;
for(int d=0;d<33;d++)
{
for(int z=0;z<50;z++)
{
for(int x=0;x<100;x+=2)
{
if(s==(d+z+x)&&s==(3*d+2*z+x/2))
{
System.out.println("d = "+d+" z = "+z+" x = "+x);
}
}
}
}

原文地址:https://www.cnblogs.com/beens/p/5218532.html