erutdioup8556
2015-10-13 18:24:37
public?class?Test9?{
public?static?void?main(String[]?args)
{
int?a,b,c;
for(a=0;a<=20;a++)
for(b=0;b<=33;b++)
for(c=0;c<=100;c++)
{
if((a*5+b*3+c==100)&&(a+b+c/3==100))
{
System.out.println(a+b+c);
}
}
}
}
2 回答
已采納

dumbaodouble
TA貢獻(xiàn)17條經(jīng)驗(yàn) 獲得超3個(gè)贊
/** ?*?編寫Java應(yīng)用程序,中國古時(shí)有人提出“百錢買百雞”, ?*?即:公雞5元一只,母雞3元一只,小雞1元三只, ?*?問:最終可買到公雞、母雞、小雞分別是多少?i,j,k ?*?i=>[1,19];j=[1,31]; ?*?(k==100-i-j)&&(15*i+9*j+k==300); ?*? ?*/ public?class?test01?{ ????public?static?void?main(String[]args){ ???????? ????????int?count=0; ????????for(int?i=1;i<=19;i++){ ????????????for(int?j=1;j<=31;j++){ ????????????????int?k=100-i-j; ????????????????if(15*i+9*j+k==300){ ????????????????????count++; ????????????????????System.out.println("第"+count+"種方案:"+"公雞"+i+"只,母雞"+j+"只,小雞"+k+"只。"); ????????????????} ????????????} ????????} ????} }

大蝦丶米
TA貢獻(xiàn)3條經(jīng)驗(yàn) 獲得超3個(gè)贊
public static void main(String[] args) {
?? ??? ?int a, b, c;
?? ??? ?for (a = 0; a <= 20; a++)
?? ??? ??? ?for (b = 0; b <= 33; b++)
?? ??? ??? ??? ?for (c = 0; c <= 300; c = c + 3) {
?? ??? ??? ??? ??? ?if (5 * a + 3 * b + c / 3 == 100 && a + b + c == 100)
?? ??? ??? ??? ??? ??? ?System.out.println("雞翁" + a + "個(gè),雞母" + b + "個(gè),雞雛" + c+ "個(gè)");
?? ??? ??? ??? ?}
?? ?}
添加回答
舉報(bào)
0/150
提交
取消