//百钱买百鸡
public class baiqianbaiji {
static void BQBJ(int m,int n)//m为钱的总数,n为鸡数
{
int z;
for(int x = 0;x <= n;x++){
for(int y = 0;y <= n; y++){
z = n- x - y;
if(z >= 0 && z % 3 == 0 && m == x * 5 + y * 3 + z / 3)
System.out.printf("公鸡: %d只,母鸡: %d只,小鸡: %d只
",x,y,z);
else{
//无法求解
}
}
}
}
public static void main(String[] args){
int m,n; //m为钱数,n为鸡数
m = 100;
n = 100;
System.out.println("百钱买百鸡问题的解决结果:");
BQBJ(m,n);
}
}