100只鸡与100元
公鸡3元1只 ,母鸡5元一只 ,小鸡3只1元用100元能组成100只鸡
//公鸡3元1只 ,母鸡5元一只 ,小鸡3只1元,用100元能组成100只鸡 public class ChickenTest { public static void showChickenNum(){ //cock 公鸡 //hen 母鸡 //chick 小鸡 for(int cock = 0;cock<=100;cock++) for(int hen=0;hen<=100-cock;hen++) for(int chick = 0;chick<=100-cock-hen;){ if(3*cock + 5*hen + chick/3 == 100 && cock+hen+chick==100){ System.out.println("公鸡:" + cock + " 母鸡:" + hen + " 小鸡:" + chick ); } chick += 3; } } public static void main(String[] args) { ChickenTest.showChickenNum(); } }