题目:公鸡3文钱,母鸡2文钱,3只小鸡1文钱,百钱买百鸡,求多少公鸡,母鸡,小鸡?

public class Work6{
public static void main(String[] args){

// 声明变量公鸡
int gj;

// 声明变量母鸡
int mj;

// 声明变量小鸡
int xj;

// 公鸡最多买(100/3)33只
for(gj = 0;gj <=33;gj++){
// 母鸡最多买50
for(mj = 0;mj <=50;mj++){
// 小鸡最多买300
for(xj = 0;xj <=300;xj++){
// x+y+z = 100; 3x+2y+z/3 = 100
if(gj + mj +xj ==100 && 9 * gj+ 6 * mj + xj == 300){
System.out.println(gj +","+ mj +","+ xj);
}
}
}
}
}
}

04-25 16:36