Kotlin program to calculate simple interest

Kotlin | Simple Interest: Here, we are implementing a Kotlin program to calculate the simple interest. Submitted by IncludeHelp, on May 12, 2020

Problem statement

Given, principal, rate, and time, we have to calculate the simple interest.

Kotlin - Calculate simple interest

Formula to calculate simple interest is: (P × R × T)/100

Where,

  • P is Principal amount.
  • R is rate of interest per annum.
  • T is time in years.

Example:

Input:
P = 5000
R = 12
T = 2

Output:
Simple Interest = 1200.0

Program to calculate simple 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.nextInt()

    //Calculate Simple Interest
    val simpleInterest = (principalAmount*rateOfInterest*time)/100

    //Print Simple Interest
    println("Simple Interest is :$simpleInterest")
}

Output

Run 1:
Enter Principal Amount : 5000
Enter Rate of Interest : 12
Enter Time : 2
Simple Interest is :1200.0
---
Run 2:
Enter Principal Amount : 500.60
Enter Rate of Interest : 12.56
Enter Time : 5
Simple Interest is :314.37680000000006

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.