# Java program to find simple interest

Let’s learn java program to find simple interest.

## Java program to find the simple interest

Simple interest program in java is the one of the frequently asked question in interview.

Simple interest is used to enumerate interest on loan in banks. It is calculated by using formula,

Also read – java reverse string array

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

In the below simple interest program in java using scanner user enters principal amount, rate and time in years.

Then using above formula simple interest is found. Let’s see simple interest program in java netbeans,

```import java.util.Scanner;

public class SimpleInterestJavaProgram
{
public static void main(String[] args)
{
float principal, rate, time;
Scanner sc = new Scanner(System.in);
System.out.print("Enter principal amount : ");
principal = sc.nextFloat();
System.out.print("Please enter rate annually : ");
rate = sc.nextFloat();
System.out.print("Please enter time(in years) : ");
time = sc.nextFloat();
float simpleInterest;
simpleInterest = (principal * time * rate) / 100;
System.out.print("The Simple Interest is : " + simpleInterest);
sc.close();
}
}

```

Output:

Calculate compound interest

Now let’s learn to calculate compound interest using java program. To calculate compound interest here’s the formula,

P (1 + R/n) (nt) – P

In compound interest formula,

R – annual interest rate

t – time

n – number of times interest is compounded. For example if ‘t’ is in years and compounded monthly then ‘n’ value is 12 and if compounded quarterly then ‘n’ value is 4.

P – principal amount

For example sachin has ₹ 200000 rupees deposited in ABC bank as fixed deposit.

The fixed deposit has an annual interest of 6 percent compounded monthly. Then compound interest after 6 years is,

P = ₹ 200000

R = 6/100 = 0.06

n = 12

t = 6

Compound interest = 200000 (1 + 0.06 / 12) (12 * 6) – 200000 = ₹ 286408.85

Here’s the java program to calculate compound interest,

```public class CompoundInterestDemo
{
public void calculateCompound(int p, int t, double r, int n)
{
double number = p * Math.pow(1 + (r / n), n * t);
double interest = number - p;
System.out.println("Compound interest after " + t + " years: " + interest);
System.out.println("Money after " + t + " years: " + number);
}

public static void main(String[] args)
{
CompoundInterestDemo obj = new CompoundInterestDemo();
obj.calculateCompound(200000, 6, .06, 12);
}
}

```

Output:

Compound interest after 6 years: 86408.8556983287
Money after 6 years: 286408.8556983287