Day 2: Operators | 30 Days of Coding | HackerRank | Java Language

**Before watching this make sure that you’ve tried enough**

Language: Java 7

import java.util.*;
import java.math.*;

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.
        double a = (tipPercent * mealCost)/100;
        double b = (taxPercent * mealCost)/100;
        double c = mealCost + a + b;
      
        // cast the result of the rounding operation to an int and save it as totalCost 
        int totalCost = (int) Math.round(c);
      
        // Print your result
        System.out.println("The total meal cost is "+totalCost+" dollars.");
    }
}

 

If this solution helped you, please share this with your friends.
And if you have anything to say, let me know in the comment section.
More solutions are coming so Like our Facebook page and Subscribe to our YouTube channel to stay connected.

Leave a Comment