Program to calculate simple interest (Java & Example)

Problem Statement ?

  • Given
    • Principal amount (P).
    • Rate of interest (R).
    • Time Period (T)
  • Find out the simple interest in Java

Example: calculate simple interest in java

Formula for Simple Interest : (Principal × Rate of Interest × Time)/100
 
Suppose,
 
Principal = 10000 dollars
 
Rate of interest = 10% per annum
 
Time Period = 5 years.
 
Simple Interest = (10000 * 10 * 5) / 100
 
Simple Interest = 5000 dollars

Program: calculate simple interest in java

package org.learn.beginner;
 
import java.util.Scanner;
 
public class SimpleInterest {
 
    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
 
            System.out.print("Enter principal amount: ");
            double principal = scanner.nextDouble();
 
            System.out.print("Enter rate of interest: ");
            double rate = scanner.nextDouble();
 
            System.out.print("Enter time in years: ");
            double time = scanner.nextDouble();
 
            double simpleInterest = (principal * rate * time) / 100;
            System.out.println("Simple Interest is :"+simpleInterest);
        }
    }
}

Output: simple interest for Principal amount is

Enter principal amount: 10000
Enter rate of interest: 10
Enter time in years: 5
Simple Interest is :5000.0