为什么我的代码在除以四分之一后不会将剩余的分数除以硬币,镍币和硬币?

时间:2017-04-02 20:41:55

标签: java

    String choice = "y";
    while(choice.equalsIgnoreCase("y")){
        if (cents <= 99 && cents > 0){
        quarters = cents / quarters;
        System.out.println("Quarters: " + quarters);

        dimes = cents / dimes;
        System.out.println("Dimes: " + dimes);

        nickels = cents / nickels;
        System.out.println("Nickels: " + nickels);

        pennies = cents / pennies;
        System.out.println("Pennies: " + pennies);

我是否需要在每个步骤后实现模数运算符?

1 个答案:

答案 0 :(得分:0)

啊,你有没有看到树木问题的木头。

老派伎俩叫做干跑

Cents Quarters Dimes Nickels Pennies Remaining Cents
41    1                              16
16             1                     6
6                       1            1
1                               1    0

你从每次计算开始。