Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Program to calculate compound interest in Kotlin

In this article, We will learn program to Calculate Compound interest in Kotlin. In simple terms, Compound interest is the sum of Principal Amount and interest of interest.

Compound Interest Formula

Source Code:
fun main(args: Array)
{
    try
    {
        print("Enter principle amount : ")
        val principle = readLine()!!
        print("Enter interest rate : ")
        val rate = readLine()!!
        print("Enter number of years : ")
        val time = readLine()!!

        val ci = principle.toDouble() * Math.pow((1 + rate.toDouble()/100.00),time.toDouble())
        println("Compound Interest is : $ci")
    }
    catch (exception : NumberFormatException)
    {
        print(exception)
    }
}
Output:
Enter principle amount : 2000
Enter interest rate : 2
Enter number of years : 3
Compound Interest is : 2122.416
Calculate Compound Interest in Kotlin - Output
Description:
In this program, we will take input from the user to enter to get principal amount, rate and years value. To do so we have used readLine() function.

compound interest formula is A = P(1 + r/n)^nt. Where "P" is the principal amount, "r" is an annual nominal interest rate and "n" is the number of years. Same is printed using print() function.


This post first appeared on Ask For Program, please read the originial post: here

Share the post

Program to calculate compound interest in Kotlin

×

Subscribe to Ask For Program

Get updates delivered right to your inbox!

Thank you for your subscription

×