/** * 百钱买百鸡:公鸡5元一只,母鸡3元一只,小鸡1元3只,问100元买100只鸡,问有多少种买法,输出每种买法的结果! * */ public class Test3 { public static void main(String[] args) { int c = 0; for (int a = 0; a < 100; a++) { for (int b = 0; b < 100; b++) { if ((7 * a + 4 * b) == 100) { c++; System.out.println("公鸡数量为:" + a + ",母鸡数量为" + b + "小鸡数量为" + (100 - a - b)); } } } System.out.println("有" + c + "种买法!"); } }
时间: 2024-10-10 05:15:21