将50元兑换成5元,2元和1元.每种面额的钱不能为0张.共有几种兑换方法.每种兑换方法的钱是怎么样的?
[Java] 纯文本查看 复制代码 public class Test2 {
public static void main(String[] args) {
int count = 0;
for (int wuYuan = 1; wuYuan < 10; wuYuan++) {
for (int liangYuan = 1; liangYuan < 25; liangYuan++) {
for (int yiYuan = 1; yiYuan < 50; yiYuan++) {
if (yiYuan*1 + liangYuan*2 + wuYuan*5 == 50)
System.out.println("一元:" + yiYuan + " 两元:" + liangYuan + " 五元:" + wuYuan);
count++;
}
}
}
System.out.println("共有" + count + "种换法");
}
} |