有一百匹马,驮一百担货,大马驮3担,中马驮2担,两只小马驮1担,问有大,中,小马各几匹?
public static void main(String[] args) {
int x1,x2,x3;//大马,中马,小马
for(x1 = 0;x1<=33;x1++) { //第一层循环是假设大马从0开始到最多33只循环
for(x2 = 0;x2<=50;x2++) { //第二层循环是假设中马从0到最多50只循环
for(x3 = 0;x3<=100;x3+=2) { //以此类推
if (x1+x2+x3==100&&3*x1+2*x2+x3/2==100) {
System.out.println("大马有"+x1+"中马有"+x2+"小马有"+x3);
}
}
}
}