我正在努力学习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 变量也一样吗?