公鸡母鸡小鸡问题

编程题:

  公鸡5元一只,母鸡3元一只,小鸡1元一只,给100元,买54只,则公鸡,母鸡,小鸡各多少只?

----------------------------------------------------

public class Test {
public static void main(String[] args) {
//x 公鸡/5元一只 y 母鸡/3元一只 z 小鸡/1元一只
System.out.println("--------------start-------------");
for(int x=0;x<=10;x++) {
for (int y= 0; y <=18; y++) {
for (int z =0; z <=54 - x - y; z++) {
if (5 * x + y * 3 + z == 100 && x + y + z == 54) {
System.out.println("公鸡:" + x + "只,母鸡:" + y + "只,小鸡:" + z + "只");
}
}
}
}
System.out.println("--------------end-------------");
}
}
-------------------------------------------
结果:

--------------start-------------
公鸡:3只,母鸡:17只,小鸡:34只
公鸡:4只,母鸡:15只,小鸡:35只
公鸡:5只,母鸡:13只,小鸡:36只
公鸡:6只,母鸡:11只,小鸡:37只
公鸡:7只,母鸡:9只,小鸡:38只
公鸡:8只,母鸡:7只,小鸡:39只
公鸡:9只,母鸡:5只,小鸡:40只
公鸡:10只,母鸡:3只,小鸡:41只
--------------end-------------

转载于:https://www.cnblogs.com/2016-cxp/p/10994914.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值