百钱白鸡问题

来源:互联网 发布:阿格里奇 知乎 编辑:程序博客网 时间:2024/05/17 08:21
package day141016;/** *总共有100元,公鸡5元1只,母鸡3元1只,小鸡1元3只; *已知公鸡、母鸡、小鸡数量相加为100只,求它们的具体数量 。 * @author XWJ * */public class MoneyAndChicken {public static void main(String[] args) {for (int x = 0; x <= 100; x++) {for (int y = 0; y <= 100; y++) {for (int z = 0; z <= 100; z+=3) {           if(x+y+z==100&&5*x+3*y+z/3==100){             System.out.printf("公鸡的数量:%d,母鸡的数量:%d,小鸡的数量:%d,\n",x,y,z);                 }}}}}}

0 0