# Calculate Simple Interest in Java

Get FREE domain for 1st year and build your brand new site

In this article, we have explained the concept of Simple Interest and implemented a program in Java to compute Simple Interest.

Table of contents:

- Concept of Simple Interest
- Simple Interest in Java

## Concept of Simple Interest

Simple interest is a basic concept in finance that relates to the amount of money charged as interest on a loan or investment. When you borrow money from a lender or invest your money in a savings account or bond, the lender or bank charges you a fee for the use of the money.

The amount of interest you pay or earn is calculated using a formula that takes into account three main factors: the principal amount, the interest rate, and the time period. Simple interest is calculated based only on the principal amount, without taking into account any interest that may have been earned or charged in previous periods.

The formula for simple interest is as follows: Simple Interest = (Principal * Interest Rate * Time) / 100 where Principal is the amount of money borrowed or invested, Interest Rate is the rate of interest charged or earned, and Time is the duration of the loan or investment in years.

For example, if you borrow $1000 from a lender at an interest rate of 5% per year for a period of 3 years, the simple interest charged on the loan would be:

Simple Interest = (1000 * 5 * 3) / 100 = $150

This means that you would have to pay back a total of $1000 + $150 = $1150 to the lender at the end of the 3-year period.

Similarly, if you invest $1000 in a savings account that pays an interest rate of 3% per year for a period of 2 years, the simple interest earned on the investment would be: Simple Interest = (1000 * 3 * 2) / 100 = $60 This means that you would earn a total of $1000 + $60 = $1060 at the end of the 2-year period.

In summary, simple interest is a basic concept in finance that is used to calculate the amount of money charged or earned as interest on a loan or investment. It is calculated using the principal amount, the interest rate, and the time period, and is a useful tool for understanding the cost or benefit of borrowing or investing money.

## Simple Interest in Java

In Java, you can calculate simple interest using the formula mentioned above by following these steps:

- First, you need to prompt the user to enter the principal amount, interest rate, and time duration using the System.out.print() method and read these values from the user using the Scanner class and its nextDouble() method.
- Next, you can calculate the simple interest using the formula Simple Interest = (Principal * Interest Rate * Time) / 100, where Principal, Interest Rate, and Time are the values entered by the user.
- Finally, you can display the result to the user using the System.out.println() method.

Hereâ€™s an example Java code snippet that demonstrates how to calculate simple interest using user input:

```
import java.util.Scanner;
public class SimpleInterest {
public static void main(String args) {
Scanner scanner = new Scanner(System.in);
// Reading inputs from the user
System.out.print("Enter the principal amount: ");
double principal = scanner.nextDouble();
System.out.print("Enter the rate of interest: ");
double rate = scanner.nextDouble();
System.out.print("Enter the time duration (in years): ");
double time = scanner.nextDouble();
// Calculating the simple interest
double simpleInterest = (principal * rate * time) / 100;
// Displaying the simple interest
System.out.println("Simple Interest = " + simpleInterest);
}
}
```

In this implementation, we first import the Scanner class to read inputs from the user. We then prompt the user to enter the principal amount, rate of interest, and time duration using the System.out.print() method.

Next, we read these values using the nextDouble() method of the Scanner class and store them in variables principal, rate, and time.

We then calculate the simple interest using the formula mentioned above and store the result in the variable simpleInterest.

Finally, we display the result to the user using the System.out.println() method.

With this article at OpenGenus, you must have the complete idea of Simple Interest in Java.