import java.util.Scanner;
public class SpecialSale {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter purchase amount (?): ");
double amount = sc.nextDouble();
double discount = 0;
double finalAmount;
// Apply 10% discount if amount is more than 1000
if (amount > 1000) {
discount = amount * 0.10;
}
finalAmount = amount - discount;
System.out.println("Original Amount: ?" + amount);
System.out.println("Discount: ?" + discount);
System.out.println("Amount to Pay: ?" + finalAmount);
sc.close();
}
}
If purchase amount > ?1000,
→ Discount = 10% of amount
Otherwise,
→ No discount
Final Amount = Amount − Discount
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.