Arithmetic Operations in Java: Explanation & Practice

Perform basic math operations

Problem summary

Calculate the total price of 3 items at $15.50 each, then apply a 10% discount.

Starter code

public class Main {
    public static void main(String[] args) {
        double itemPrice = 15.50;
        int quantity = 3;
        double discount = 0.10;
        
        // Calculate total and discounted price
        // Print: Total: $46.5
        // Print: After discount: $41.85
    }
}

Expected output and test cases

  • Calculate discounted total
    Total: $46.5
    After discount: $41.85

Hints

  1. Multiply itemPrice by quantity for total
  2. Calculate discount amount: total * discount
  3. Subtract discount from total for final price

Related Core Java Basics exercises

Practice all Core Java Basics exercises · Run this idea in the Java compiler