我可以做哪些改变来通过这个?

What changes can I make to pass this?

我卡在第 2 天:关于 hackerrank 的操作员问题。 这是任务:

Given the meal price (base cost of a meal), tip percent (the percentage of the meal price being added as tip), and tax percent (the percentage of the meal price being added as tax) for a meal, find and print the meal's total cost. Round the result to the nearest integer.

这是我的代码:

import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

class Result {
    public static void solve(double meal_cost, int tip_percent, int tax_percent) {

    // Write your code here
   {
   long total=0;double tip;double tax;

    

   tip = meal_cost*tip_percent/100;
   tax = tax_percent*tip_percent/100;
   total =Math.round(meal_cost+tip+tax);
   
   System.out.println(total);
   }
    }
}
//provided by hackerrank.
public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

        double meal_cost = Double.parseDouble(bufferedReader.readLine().trim());

        int tip_percent = Integer.parseInt(bufferedReader.readLine().trim());

        int tax_percent = Integer.parseInt(bufferedReader.readLine().trim());

        Result.solve(meal_cost, tip_percent, tax_percent);

        bufferedReader.close();
    }
}

screenshot

两件事:

首先,您的解决方案看起来不错,只是税收计算不小心使用了错误的数字 — 看看。

其次:我不明白提供的答案和提供的模板是如何匹配的,因为模板接受参数,而提供的答案从标准输入读取数据——你确定你没有搞混吗?

在税收计算中,您使用的是 tip_percent 而不是 meal_cost。

通过更改 tax = meal_cost*tax_percent/100;

修复 Result.solve

希望对您有所帮助!