1. Hundred-dollar white chicken
1 for(intGJ =0;gj<=100;gj++)2 {3 for(intMJ =0;mj<=100;mj++)4 {5 for(intCJ = 0;cj<=300;cj++)6 {7 if((gj+mj+cj==100) && (5*gj+3*mj+cj/3.0) ==100)8 {9System.out.println ("gj=" +gj+ "mj=" +mj+ "cj=" +CJ);Ten } One A } -}
View Code
Gj=0mj=25cj=75
gj=4mj=18cj=78
gj=8mj=11cj=81
gj=12mj=4cj=84
2. Number of daffodils
1 for(intBw =1;bw<=9;bw++)2 {3 for(intsw=0;sw<=9;sw++)4 {5 for(intgw=0;gw<=9;gw++)6 7 {8 if((BW*BW*BW+SW*SW*SW+GW*GW*GW) = = (bw*100+sw*10+gw*1))9 {TenSystem.out.println (bw*100+sw*10+gw*1); One } A } -}
View Code
153
370
371
407
3. Hundred Horses
1 //TODO Auto-generated method stubs2 for(intdma=0;dma<=100;dma++)3 {4 for(intzma=0;zma<=100;zma++)5 {6 7 for(intxma=0;xma<=200;xma++)8 {9 if(((Dma+zma+xma) ==100) && (3*dma+2*zma+xma/2.0) ==100)Ten { OneSystem.out.println ("Big horse number is" +dma+ "\ T in ma number is" +zma+ "\ t Pony number is" +Xma); A } -}
View Code
The big horse number is 2 the horse number is 30 the pony number is 68
The big horse number is 5 the horse number is 25 the pony number is 70
The big horse number is 8 the horse number is 20 the pony number is 72
The big horse number is 11 the horse number is 15 the pony number is 74
The big horse number is 14 the horse number is 10 the pony number is 76
The big horse number is 17 the horse number is 5 the pony number is 78
The big horse number is 20 the horse number is 0 the pony number is 80
1.6 Java application of the brute-lifting method