题:100钱买100只鸡,必须满足,钱花完,鸡百只
重点:循环语句来枚举所有可能性
代码:
byte plan = 1;for (int i = 0; i < 20; i++) {
for (int i1 = 0; i1 < 34; i1++) {
for (int i2 = 0; i2 < 101; i2++) {
if (((i * 5 + i1 * 3 + i2) == 100) && ((i + i1 + i2*3) == 100)) {
System.out.println("方案" + plan + ":\n买5元一只的母鸡:"+i + "只\n买3元一只的公鸡:" + i1 + "只\n买1元三只的小鸡:" + i2*3 + "只\n");
plan++;
}
}
}
} 标签:Java,买百鸡,百钱,i2,++,i1,int,plan,100 From: https://www.cnblogs.com/Lee597/p/17603928.html