Q:

Kotlin program to calculate compound interest

belongs to collection: Kotlin Basic Programs

0

Compound interest is the sum of principal amount and interest of interest.

Given, principal, rate, and time, we have to calculate the 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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Kotlin Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Kotlin program to calculate and display student gr... >>
<< Kotlin program to calculate simple interest...