Kotlin program to find Quotient and Remainder

In this post, we will go through Kotlin program to find quotient and remainder when dividend is divided by divisor.
In other words, we are going to find quotient and remainder when a number is divided by another number in kotlin.

Kotlin program to find Quotient and Remainder

Sourcecode –

import java.util.*

fun main() {

    val read = Scanner(System.`in`)

    println("Enter dividend:")
    val dividend = read.nextInt()

    println("Enter divisor:")
    val divisor = read.nextInt()

    val quotient = dividend / divisor
    val remainder = dividend % divisor

    println("Quotient = $quotient")
    println("Remainder = $remainder")
}

When you run the program, output will be

Enter dividend:
25
Enter divisor:
3
Quotient = 8
Remainder = 1
Explanation:

At first, we are accepting two inputs (Dividend and Divisor) from user.
read.nextInt() method is being used to read input from user. So,
val dividend = read.nextInt() means read the value entered by user and store it in variable
dividend.

Similarly, we read the value(i.e. divisor) entered by user and stored it in divisor.

/ operator is used to get quotient when a number is divided by other number. So,
dividend / divisor will return quotient when dividend is divided by divisor.

% operator is used to get remainder when a number is divided by other number. So,
dividend % divisor will return remainder when dividend is divided by divisor.

Leave a Reply