Java Program To Calculate Discount Of Product | Programs
Beginners Programs :

Java Program To Calculate Discount Of Product | Programs

Java program to calculate discount of a product. With the help of the following program you can calculate the discount of a product instantly. The following code has been written in five different ways. By using standard values, using command line arguments, while loop, do while loop, user define method and creating a separate class.

How to calculate a discount of a product ?

A:  Discount is defined as the deduction in the price something you sell to the customers.  Most of the disocunt rate is given in percentage rate.

Here is the formula to calculate the discount:

Discount = List price x Discount Rate

For example :

A pen costs 50$ and it is been sold with a discount of 12%, what is the discount price of the pen ?

A: = 50 x 12/100

= 50 × 0.12

= $ 6

Discount price of the pen is : 44$. Hope you get it.

Okay fine ! Let’s get into the programming for the above equation is different formats.

Discount Java Code

1. Java program to calculate Discount ( Using standard values )

By using standard values consider this program is universal code.


2. Taking inputs through scanner classs

Taking inputs through scanner class, with sample output.


3. By Using Command Line Arguments

There you go another method: By using command line arguments. If yo no idea about command line arguments you can check out here – command line arguments with examples.


4.User Define Method

By using user define method. Here you go:


5. Inputs Through Scanner Class

Java code for getting discount of product through creating a separate class( ) and taking inputs through scanner class.

That’s it. If you got any new idea to write the above code in more than 5 five ways apart from mentioned above do share it below by commenting .

More programs :

  • lyoussi abdel karim

    Thanks for this short but yet pinpointing tutorial.