00:00

Java Program to Calculate Simple Interest

Last updated: 2 min read

Simple interest is interest calculated only on the original amount (the principal), not on interest already earned. The formula is:

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

  • P is the principal amount,
  • R is the rate of interest per year, in percent,
  • T is the time in years.

For example, 10,000 deposited for 5 years at 7.5% earns 10000 × 7.5 × 5 / 100 = 3,750 in interest, so the total amount is 13,750.

1. Simple Interest with Fixed Values

The values are written in the program. double is used because the rate and the result can have decimals.

SimpleInterest.java
public class SimpleInterest {
    public static void main(String[] args) {
        double principal = 10000;
        double rate = 7.5;
        double time = 5;

        double interest = (principal * rate * time) / 100;
        double amount = principal + interest;

        System.out.println("Principal: " + principal);
        System.out.println("Rate: " + rate + "% per year");
        System.out.println("Time: " + time + " years");
        System.out.println("Simple interest: " + interest);
        System.out.println("Total amount: " + amount);
    }
}
Output
Principal: 10000.0
Rate: 7.5% per year
Time: 5.0 years
Simple interest: 3750.0
Total amount: 13750.0

2. Simple Interest with User Input

This version reads the values with Scanner, puts the formula in a method, and prints the results with two decimal places using printf().

SimpleInterestInput.java
import java.util.Scanner;

public class SimpleInterestInput {

    static double simpleInterest(double principal, double rate, double years) {
        return principal * rate * years / 100;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the principal amount: ");
        double principal = scanner.nextDouble();
        System.out.print("Enter the rate of interest (% per year): ");
        double rate = scanner.nextDouble();
        System.out.print("Enter the time (in years): ");
        double years = scanner.nextDouble();
        scanner.close();

        double interest = simpleInterest(principal, rate, years);

        System.out.printf("Simple interest: %.2f%n", interest);
        System.out.printf("Total amount: %.2f%n", principal + interest);
    }
}
Output (with sample input)
Enter the principal amount: 700000
Enter the rate of interest (% per year): 6.4
Enter the time (in years): 10
Simple interest: 448000.00
Total amount: 1148000.00

3. Summary

  • Simple interest = P × R × T / 100, where R is a yearly percentage and T is in years.
  • The total amount at the end is the principal plus the interest.
  • Use double for money calculations in simple programs, and printf("%.2f") to show two decimals.
  • For financial software, BigDecimal avoids rounding errors.

Related Programs