Java Program to Calculate Discounted Price
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
// create scanner class object
Scanner sc = new Scanner(System.in);
// prompt user to enter original price
System.out.print("Enter original price: ");
double originalPrice = sc.nextDouble();
// prompt user to enter discount percentage
System.out.print("Enter discount percentage: ");
double discountPercentage = sc.nextDouble();
// calculate discounted price
double discountedPrice = originalPrice - (originalPrice * discountPercentage / 100);
// display discounted price
System.out.println("Discounted price is " + discountedPrice);
}
}
Output:
Enter original price: 500
Enter discount percentage: 10
Discounted price is 450.0
