# Kotlin Program to Calculate Simple Interest

Kotlin Server Side ProgrammingProgramming

#### Kotlin Online Training

68 Lectures 4.5 hours

#### Kotlin Masterclass Programming: Android Coding Bible

71 Lectures 5.5 hours

#### Android Dependency Injection using Dagger with Kotlin

18 Lectures 1.5 hours

In this article, we will understand how to calculate the Simple Interest in Kotlin. It is the percentage interest on total principal amount. Returns are less compared to Compound Interest. Simple Interest is calculated using the formula

(principle*rate*time)/100


Below is a demonstration of the same

Suppose our input is

Principle number: 100000
Interest rate: 5
Time period in years: 2


The desired output would be

Simple Interest: 1000


## Algorithm

• Step 1 − START

• Step 2 − Declare four integer values principalAmount, interestRate, timePeriod, simpleInterest

• Step 3 − Define the values for principalAmount, interestRate, timePeriod, simpleInterest

• Step 4 − Perform “(principle*rate*time)/100” to calculate the simple interest and store it in a simpleInterest variable

• Step 5 − Display simpleInterest

• Step 6 − STOP

## Example 1

In this example, we will calculate Simple Interest in Kotlin using the above given formulae. First, declare and set the variable for the Principal amount

val principalAmount = 10000


Then, set the variables for rate of interest and time period −

val interestRate = 5
val timePeriod = 3


Now, use the above formulae to calculate the Simple Interest with the Principal, Rate of Interest and Time Period −

val simpleInterest = (principalAmount*interestRate*timePeriod)/100


Let us now see the example to compute the Simple Interest in Kotlin −

fun main() {

val principalAmount = 10000
println("Principal amount is defined as: $principalAmount") val interestRate = 5 println("The rate of interest is defined as:$interestRate %")

val timePeriod = 2
println("The time period is defined as: $timePeriod years") val simpleInterest = (principalAmount*interestRate*timePeriod)/100 println(" Simple Interest is:$simpleInterest")
}


## Output

Principal amount is defined as: 10000
The rate of interest is defined as: 5 %
The time period is defined as: 2 years

Simple Interest is: 1000


## Example 2

In this example, we will calculate Simple Interest in Kotlin −

fun main() {
val principalAmount = 10000
println("Principal amount is defined as: $principalAmount") val interestRate = 5 println("The rate of interest is defined as:$interestRate %")

val timePeriod = 2
println("The time period is defined as: $timePeriod years") getSimpleInterest(principalAmount, interestRate, timePeriod) } fun getSimpleInterest(principalAmount: Int, interestRate: Int, timePeriod: Int) { val simpleInterest = (principalAmount*interestRate*timePeriod)/100 println(" Simple Interest is:$simpleInterest")
}


## Output

Principal amount is defined as: 10000
The rate of interest is defined as: 5 %
The time period is defined as: 2 years

Simple Interest is: 1000

Updated on 13-Oct-2022 12:53:38