Home »
Kotlin »
Kotlin Programs »
Kotlin Basic Programs
Kotlin program to calculate compound interest
Kotlin | Compound Interest: Here, we are implementing a Kotlin program to calculate the Compound interest.
Submitted by IncludeHelp, on May 12, 2020
Compound interest is the sum of principal amount and interest of interest.
Problem statement
Given, principal, rate, and time, we have to calculate the Compound interest.
Kotlin - Calculate compound interest
Formula to calculate Compound interest is: P * (Math.pow(( 1 + R/100), T)
Where,
- P is Principal amount.
- R is rate of interest per annum.
- T is time in years.
Example:
Input:
P = 5000
R = 12
T = 5
Output:
Compound Interest = 8811.708416000003
Program to calculate Compound interest in Kotlin
package com.includehelp
import java.util.*
//Main Function , Entry point of Program
fun main(args: Array<String>) {
//Input Stream
val scanner = Scanner(System.`in`)
//Input Amount
print("Enter Principal Amount : ")
val principalAmount = scanner.nextDouble()
//Input Interest Rate
print("Enter Rate of Interest : ")
val rateOfInterest = scanner.nextDouble()
//Input time in years
print("Enter Time : ")
val time = scanner.nextDouble()
//Calculate Compound Interest
val compoundInterest = principalAmount.toDouble() * Math.pow((1 + rateOfInterest.toDouble()/100.00),time.toDouble())
//Print Compound Interest
println("Compound Interest is :$compoundInterest")
}
Output
Enter Principal Amount : 5000
Enter Rate of Interest : 12
Enter Time : 5
Compound Interest is :8811.708416000003