Java Program to Calculate simple interest

Formula to calculate simple interest

Java program to calculate simple interest has been shown here. Simple interest is the amount of interest which is calculated based on the initial principal, interest rate and time (in years). It is determined by using following formula:


$SI = {\Large \frac{p * r * t}{100}}$


Here $SI$ represents simple interest. Pricipal amount, annual interest rate and time have been represented by $p$, $r$ and $t$ respectively. As an example, let's assume $p = 1000$, $r = 5$ and $t = 2$ then by using above formula, we get the value of simple interst $SI = 100$.






1. Java Program & output to calculate simple interest

Code has been copied
/***************************************
        alphabetacoder.com
Java program to compute simple interest
**************************************/

import java.util.Scanner;
public class SimpleInterest{
    public static void main(String args[]){
        float p,r,t,si;
        //System.in is a standard input stream
        // sc is the object
        Scanner sc= new Scanner(System.in);
        
        //take input of principal, interest rate and time
        System.out.print("Enter principal amount= ");
        p=sc.nextFloat();
        System.out.print("Enter interest rate= ");
        r=sc.nextFloat();
        System.out.print("Enter time= ");
        t=sc.nextFloat();
        
        //calculate simple interest
        si=p*r*t/100;
        
        //print result
        System.out.print("Simple interest= "+si);
    }
}

Output


Enter principal amount= 5000

Enter interest rate= 3.5

Enter time= 5

Simple interest= 875.0