Table of Contents
Introduction
This article illustrates that a Java program can calculate compound interest on a sum of money.
The formula to calculate compound interest on a sum of money is as follows:
Compound Interest = P (1 + R/100) ^ r
where,
P is the principal Amount
R is the rate of interest
T is the time span.
Example
Input: Principle (amount): 1200
Time: 2
Rate: 5.4
OUTPUT: Compound Interest = 1333.099243
Sample Code
//Java Program to find compound interest for the given values import java.io.* class Demo { public static void main (String args []) { double principle = 1200, rate = 5.4, time = 2; //Calculate Compound Interest double CI = principle * (Math.pow ( (1 + rate / 100), time)); System.out.println (“Compound Interest is: ” + CI); } }
OUTPUT
Compound Interest is 1333.099243
0 Comments