一个简单的算法..问题..
class SM
{
public static void main(String[] args)
{
double a=0.0,b=0.0,c=0.0,d=0.0;
System.out.println( "Result as fallows: ");
//for part-----------------------
System.out.println( "\t--for-- ");
for(a=0.0;a <=8.0;a+=0.5)
{
for (b = 0.0; b <= 8.0; b += 0.5)
{
for (c = 0.0; c <= 8.0; c += 0.5)
{
d = 8.0 - a - b - c;
if (a * b * c * d == 8.0 && a + b + c + d == 8.0)
{
System.out.print( "==> > : ");
System.out.println( "a= " + a + ",b= " + b + ",c= " + c + ",d= " + d);
//System.exit(0);
}
}
}
}
//while part-----------------------
System.out.println( "\t--while-- ");
a = 0.0;
while (a <= 8.0)
{
b = 0.0;
while(b <= 8.0)
{
c = 0.0;
while(c <= 8.0)
{
d = 8.0 - a - b - c;
if (a * b * c * d == 8.0 && a + b + c + d == 8.0)
{
System.out.print( "==> > : ");
System.out.println( "a= " + a + ",b= " + b + ",c= " + c + ",d= " + d);