We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
here is code if anyone stuck in java
import java.io.;
import java.math.;
import java.security.;
import java.text.;
import java.util.;
import java.util.concurrent.;
import java.util.function.;
import java.util.regex.;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
class Result {
/*
* Complete the 'solve' function below.
*
* The function accepts following parameters:
* 1. DOUBLE meal_cost
* 2. INTEGER tip_percent
* 3. INTEGER tax_percent
*/
public static void solve(double meal_cost, int tip_percent, int tax_percent) {
// Write your code here
double tip = (meal_cost * tip_percent) / 100;
double tax = (meal_cost * tax_percent) / 100;
//double total_cost = meal_cost + tip + tax;
int total_cost = (int) Math.round(meal_cost + tip + tax);
double round = (int) Math.round(total_cost);
if(round < 0.5){
System.out.println((int)(meal_cost+tip+tax)+1);
}else{
System.out.println((int)(meal_cost+tip+tax));
}
}
}
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();
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 2: Operators
You are viewing a single comment's thread. Return to all comments →
here is code if anyone stuck in java import java.io.; import java.math.; import java.security.; import java.text.; import java.util.; import java.util.concurrent.; import java.util.function.; import java.util.regex.; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList;
class Result {
}
public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
}