# 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-defined method and creating a separate class.

How to calculate a discount on a product?

A:  Discount is defined as the reduction in the price something you sell to the customers.  Most of the discount 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 at 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.

output:

### 2. Taking inputs through scanner classs

Taking inputs through scanner class, with sample output.

output:

#### 3. By Using Command-Line Arguments

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

output:

4.User Define Method

By using user-defined method. Here you go:

output:

##### 5. Inputs Through Scanner Class

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

output
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 :