Skip to content

← Back to Overview

Java Program - Simple Interest Calculator

Concept Explanation

What is it?

Simple interest is a quick and easy method of calculating the interest charge on a loan or investment. It is determined by multiplying the daily interest rate by the principal by the number of days that elapse between payments.

Formula

$\(SI = \frac{P \times R \times T}{100}\)$ Where: - P = Principal amount - R = Rate of interest per annum - T = Time (in years)


Algorithm

  1. Start
  2. Declare variables for Principal (p), Rate (r), Time (t), and Interest (si).
  3. Accept or initialize input values.
  4. Apply the formula: si = (p * r * t) / 100.
  5. Display the result.
  6. End

Implementations

import java.util.Scanner;

public class SimpleInterest {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter Principal Amount: ");
        double p = sc.nextDouble();

        System.out.print("Enter Annual Interest Rate (%): ");
        double r = sc.nextDouble();

        System.out.print("Enter Time (Years): ");
        double t = sc.nextDouble();

        double si = (p * r * t) / 100;

        System.out.println("-------------------");
        System.out.println("Simple Interest: " + si);
        System.out.println("Total Amount: " + (p + si));

        sc.close();
    }
}

Explanation

  • Java
  • Uses java.util.Scanner for user input.
  • Uses double data type to handle decimal values for precision.
  • Ensures the formula order follows PEMDAS.

Complexity Analysis

  • Time Complexity: O(1)
  • Space Complexity: O(1)

Sample Dry Run

Principal Rate Time Calculation Output
1000 5 2 (1000 * 5 * 2) / 100 100


"Interest on debts is inventory's cousin." - Anonymous