** ** das falsche Essen bekommen kosten
der Mahlzeit Preis (Grundkosten einer Mahlzeit) In Anbetracht Spitze Prozent (der Prozentsatz der Mahlzeit Preis als Spitze hinzugefügt werden), und Steuer Prozent (der Prozentsatz der Mahlzeitpreis, der als Steuer addiert wird) für eine Mahlzeit, findet und druckt die Gesamtkosten der Mahlzeit.
Hier ist mein Code
public class Solution3 {
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
double tip = mealCost *(tipPercent/100);
double tax = mealCost*(taxPercent/100);
double total= mealCost+tip+tax;
// cast the result of the rounding operation to an int and save it as totalCost
int totalCost = (int) Math.round(total);
System.out.println("The total meal cost is "+totalCost+" dollars");
}
}
Erwartete Ausgabe
The total meal cost is 15 dollars.
Meine Ausgabe
The total meal cost is 12 dollars.
Bitte helfen Sie mir.
Jede Hilfe wäre willkommen.
Sie Integer-Division zu tun, die Dezimalstellen abschneidet. Probieren Sie stattdessen '/ 100.0' aus. – shmosel
Danke Mann, es hat funktioniert. –
Mögliche Duplikate von [Division von ganzen Zahlen in Java] (http://stackoverflow.com/questions/7220681/division-of-integers-in-java) – shmosel