double tip = 12*20/100;
ręcznie licząc na kalkulatorze wychodzi 2.4
program liczy 2.0
robię zadanie z https://www.hackerrank.com/challenges/30-operators/tutorial
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
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.
mealCost = 12.00;
tipPercent=20;
taxPercent=8;
double tip = 12* tipPercent/100;
double tax = 12 * taxPercent/100;
// cast the result of the rounding operation to an int and save it as totalCost
double total = mealCost + tip + tax;
System.out.println(tip);
int totalCost = (int) Math.round(total);
// Print your result
System.out.println("The total meal cost is " + totalCost + " dollars.");
}
}
Sample Input
12.00
20
8
Sample Output
The total meal cost is 15 dollars.
Explanation
Given:
mealCost=12 , tipPercent=20 , taxPercent=8t
Calculations:
tip=12×20100=2.4
tax=12×8100=0.96
totalCost=mealCost+tip+tax=12+2.4+0.96=15.36
round(totalCost)=15
We round totalCosttotalCost to the nearest dollar (integer) and then print our result:
The total meal cost is 15 dollars.
ciąglę mi kompiluje tip jako 0.0
jeżeli dam zamiast int tipPercent na double tipPercent to wychodzi dobrze ale w zadaniu nie mogę nic ruczać powyżej 1 komentarza