# Java Program to calculate simple interest

Here we are explaining how to write a Java program to find the simple interest. So first we have to read the principal amount, interest per year, and time period in a year from the user. Then we can calculate the simple interest.

We recommend you the following topics of Java for a better understanding of the program.

## What is the formula for calculating simple interest?

We can calculate the simple interest by using the formula,

Simple Interest=(P * R * T )/100

where P is the Principal amount.

R is the Interest rate per Annum.

T is the time period in years.

## How to read a float number in java?

For reading a float number from the user in java, we can use the `nextFloat()` function in the java Scanner class. In this program, we have to read the principal amount, interest rate, time as a `float`. So we have to write the code as follows:

``````
System.out.print("Enter the Principal amount : ");
p = sc.nextFloat();
```
```

## How to implement the java program to calculate simple interest?

First, we have to declare the class SimpleInterest.Then open the main function. Then declare the variables p,r,t, si as `float`. Read the principal amount from the user into the variable p. Read the rate of interest per annum in the variable r. Read the time period in a year from the user into the variable t. Then calculate simple interest as si=p*n*r/100.Then display simple interest as si using the `system.out.println()` function.

### ALGORITHM

STEP 1: Declare the class SimpleInterest with a public modifier.

STEP 2: Open the `main()` to start the program, Java program execution starts with the `main()`

STEP 3: Declare the variables p,r,t,si as float.

STEP 4: Read the principal amount from the user into the variable p.

STEP 5: Read the rate of interest in the variable r.

STEP 6: Read the time period in the variable t.

STEP 7: Calculate si=p*i*t/100.

STEP 8: Display simple interest as si.

## Java Source Code

```                                          ```import java.util.Scanner;
public class SimpleInterest
{
public static void main(String args[])
{
float p, r, t,si;
Scanner sc = new Scanner(System.in);
System.out.print("Enter the Principal amount : ");
System.out.print("Enter the Rate of interest per year : ");
r = sc.nextFloat();//Read rate of interset
System.out.print("Enter the Time period in year : ");
t = sc.nextFloat();//Read the time period
sc.close();
si = (p * r * t) / 100;//calculate the simple interest
System.out.print("Simple Interest is: " +si);
}
}```
```

## OUTPUT

```OUTPUT 1

Enter the Principal amount :3000
Enter the Rate of interest per year : 7
Enter the Time period in year : 4
Simple Interest is:840.0

OUTPUT 2

Enter the Principal amount :6000
Enter the Rate of interest per year : 10
Enter the Time period in year : 5
Simple Interest is:3000.0
```
VIEW ALL
VIEW ALL
VIEW ALL