Java中的算术:我的等式出了什么问题?

时间:2016-12-05 11:35:39

标签: java math

我正在努力学习Java并想出了这个挑战 - 算术

我的代码如下:

public class Arithmetic {

public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    double mealCost = scan.nextDouble(); // original meal price
    int tipPercent = scan.nextInt(); // tip percentage
    int taxPercent = scan.nextInt(); // tax percentage
    scan.close();

    // Write your calculation code here.
    double tip = mealCost * (tipPercent / 100);
    double tax = mealCost * (taxPercent/100);
    double totalGeneralCost = mealCost + tip + tax;


    // cast the result of the rounding operation to an int and save it as totalCost 
    int totalCost = (int) Math.round(totalGeneralCost);

    // Print your result
    System.out.println(tax);
}

}

当然有一个输入,为什么我的 tip 变量返回0? tax 变量也一样吗?

0 个答案:

没有答案