问题:今有鸡翁一,值钱伍;鸡母一,值钱三;鸡鶵三,值钱一。凡百钱买鸡百只,问鸡翁、母、鶵各几何?
package com.yc.bean;
/**
*
* @author baibing
*
*/
public class Chikentest {
public static void main(String[] args) {
//今有鸡翁一,值钱伍;鸡母一,值钱三;鸡鶵三,值钱一。凡百钱买鸡百只,问鸡翁、
// 母、鶵各几何?
int boy,girl,son;
for(boy = 0;boy<=20;boy++){//假设全部买成公鸡,最多能买20只
for (girl = 0;girl<34;girl++) {//假设全部买成母鸡,最多能买33只
for(son = 0;son<=300;son++){//假设全部买成鸡仔,最多能买300只
//如果满足条件则打印出来
if(boy*5 + girl*3 + son/3 == 100 && boy+girl+son == 100 && son%3==0){
System.out.println("公雞:" + boy + "母雞:" + girl + "雞仔:" + son);
}
}
}
}
}
}
公雞:0母雞:25雞仔:75
公雞:4母雞:18雞仔:78
公雞:8母雞:11雞仔:81
公雞:12母雞:4雞仔:84