public class demo6 {
public static void main(String[] args) {
System.out.print("请输入你要输入的金额:");
Scanner in = new Scanner(System.in);
int amount = in.nextInt();
OUT:
for (int one = 0; one <= amount; one++) {
for (int five = 0; five <= amount; five++) {
for (int ten = 0; ten <= amount; ten++) {
for (int twenty = 0; twenty <= amount; twenty++) {
if (one + five * 5 + ten * 10 + twenty * 20 == amount) {
System.out.println(one + "张1元\t" + five + "张5元\t" + ten + "张10元\t" + twenty + "张20元\t"+"\t总金额:"+amount);
break OUT;
}
}
}
}
}
}
}
运行代码截图