1 //Hundred -Horse hundred-dollar similar to the question of hundred chicken, poor lift2 3 for(intDM =0;dm<=33;dm++)//the number of horses, the first layer of circulation4 5 {6 for(intZM =0;zm<=50;zm++)//The number of the horses, the second layer of circulation7 8 {9 for(intXM = 0; xm<=200;xm++)//the number of ponies, the third cycleTen One { A if(dm+zm+xm==100&&dm*3+zm*2+xm/2.0==100) - { -System.out.println ("The number of large horses is" +dm+ "\ T in the number of horses is" +zm+ "\ t Pony number is" +XM); the } - } - } - } + - + //Hundred-dollar hundred chicken problem A at for(intcock=0;cock<=20;cock++)//the first layer of the Rooster cycle - - { - for(intHen =0;hen<=34;hen++)//The cycle of a hen as a second layer - - { in intChick = 100-hen-cock;//calculate the number of chicks - to if((5*cock + 3*hen +chick/3.0) ==100)//Judging whether it meets the requirements of hundred dollars + - { the //outputs the number of three chickens that meet the requirements *System.out.println ("The number of cocks is" +cock+ ", the number of hens is" +hen+ ", the number of chicks is" +chick); $ }Panax Notoginseng } - } the + A //Narcissus number, exhaustive all the three digits of the + for(intb = 1;b<=9;b++)//the cycle of the Hundred numbers - $ { $ for(ints = 0;s<=9;s++)//10-digit loop - - { the for(intg = 0;g<=9;g++)//Single -digit loop - Wuyi { the if(B*B*B+S*S*S+G*G*G==B*100+S*10+G)//determine if the condition is met - { WuSystem.out.println (b*100+s*10+g); - About } $ } -}
View Code
Three exhaustive exercises
Hundred Horses + Hundred money hundred Chicken + Narcissus number--------"Poor lifting" of three exercises