不知道什么是错的......(更换机器)

时间:2015-10-22 11:30:38

标签: java

我刚刚开始使用java进行编码,我正在开发一个更改机器-esk程序。我知道它可以被浓缩,但它是约束的一部分。 它不会随机变更欠款和季度数......

import java.util.Scanner;
public class Change {

    public static void main(String[] args) {
        double costVar, paidVar, amountOwed;//user defined

        //defining the vale of US coins 
        final double quarterCoin = 0.25;
        final double dimeCoin = 0.10;
        final double nickelCoin = 0.05;
        final double pennyCoin = 0.01;

        //Variable for math stuff
        double quarterAmountdec, dimeAmountdec, nickelAmountdec, pennyAmountdec;
        short quarterAmountfin, dimeAmountfin, nickelAmountfin, pennyAmountfin;

        Scanner keyboard = new Scanner(System.in);

        //ask the user to input costs and amount payed (assuming the amount paid is > or = the cost of the item)
        System.out.println("Enter Item Cost: ");
        costVar=keyboard.nextDouble();
        System.out.println("Enter Amount Paid: ");
        paidVar=keyboard.nextDouble();

        amountOwed = paidVar - costVar;//math for the changed owed
        System.out.println("\nChange Owed: $" +amountOwed++);//displaying how much change the machine owes

        //math to calculate the coins owed (involves intentional loss of accuracy

        quarterAmountdec = amountOwed / quarterCoin;
        quarterAmountfin = (short)quarterAmountdec;

        //outputs coins owed
        System.out.println("Quarters: " +quarterAmountfin++ );
    }

}

输出:

  

输入项目成本:
  2.34
  输入支付金额:
  6.89

     

变更欠款:4.55美元   宿舍:22

1 个答案:

答案 0 :(得分:1)

以下行改变了打印后的欠款

tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 100 // or whatever your estimated row height is. This does not have to be precise

因此,当打印欠款时看起来很好,但内部价值会改变。我个人不确定在double上调用++的行为,但我建议删除++并重新运行代码。