//这题上初中时,笔算过,完全是数字拼出来,亲戚给的题,盛情之下,算术不好也得做,很蛋疼回忆,拼了一个小时一个答案,今天在程序中算出的答案排上天了
for (int a = 0; a <= 300; a++) {// a一两的,如果全是一两的鱼,1000条
for (int b = 0; b <= 300; b++) {// b是2两的, 如果全是2两的鱼,500条
for (int c = 0; c <= 300; c++) {// c是5两的, 如果全是5两的鱼,200条
for (int d = 0; d <= 300; d++) {// d是10两的, 如果全是10两的鱼,100条
if ((a * 1 + b * 2 + c * 5 + d * 10) == 1000
&& (a + b + c + d) == 300 && a != 0 && b != 0
&& c != 0 && d != 0) {
System.out.println(a + "条," + b + "条," + c + "条,"
+ d + "条");
Thread.sleep(20);
}
}
}
}
} |