运算和语句,例题5,百钱买百鸡
鸡翁一,值钱五;鸡母一,值钱三;鸡雏三,值钱一。
百钱买百鸡,求鸡翁,鸡母,鸡雏各几何?
1: //百鸡问题
2: /*
3: jw*15 + jm*9 + jc = 300
4: jw + jm + jc = 100
5: ->
6: jc = 100 - jw - jm
7: 7jw + 4jm = 100
8: */ www.zzzyk.com
9: public class t2_11{
10: public static void main(String argv[]){
11: int jw,jm,jc;
12: for(jw=0;jw<=20;jw++)
13: {
14: jm = (100-7*jw)%4;
15: if(jm!=0)
16: continue;
17: jm = (100-7*jw)/4;
18: if(jm<0)
19: continue;
20: jc = 100-jw-jm;
21: System.out.println("jw = "+jw+" jm = "+jm+" jc = "+jc);
22: }
23:
24: }
25: }
作者:showcolors
补充:软件开发 , Java ,