java - 如何解决问题以匹配 Java 中的预期输出?
问题描述
税前餐费和小费为12.00,餐费税率为20%,餐费为8%。您需要使用 Scanner 类来接收来自用户的输入。
12.00
20
8
预期的输出是:
15
我尝试了不同的方法,特别是使用下面的代码,但我得到了不同的结果。我不能像预期的那样得到 15 。
enter public class MealSolution {
private static final Scanner scanner = new Scanner(System.in);
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.print("Enter cost of meal: ");
double meal_cost = scanner.nextDouble();
System.out.print("Enter the tip percent: ");
int tip_percent = scanner.nextInt();
System.out.print("Enter tax of meal: ");
int tax_percent = scanner.nextInt();
double tip = meal_cost * tip_percent/100;
double tax = meal_cost * tax_percent/100;
double cost = meal_cost + tip + tax;
long total_cost = Math.round(cost);
System.out.println(total_cost);
scanner.close();
}
}
解决方案
要获得总成本,请计算餐费并加上小费和税金。
double cost = meal_cost + tip + tax;
推荐阅读
- corda - 在重新部署的 Corda Enterprise App 上发布更新状态
- react-native - React Native App 作为 Tcp 客户端
- scala - 如何使用scala为spark数据框中的列添加前缀和后缀值
- php - 如何在 Web 服务器上显示 Plivo 短信文本?
- php - Laravel5.6 phpexcel包安装报错
- python - 清理python中的列
- sql-server - 如何在 Angular 6 中使用 Sql 服务器连接?
- python - Python从列表中删除常用词
- jquery - 主干视图中的多个 jQuery 对象
- vue.js - 是否有可能让哪个组件调用一些动作 Vuex?