English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Complete Collection of Kotlin Examples
In this program, you will learn how to calculate the quotient and remainder based on the given divisor and dividend in Kotlin.
fun main(args: Array<String>) { val dividend = 25 val divisor = 4 val quotient = dividend / divisor val remainder = dividend % divisor println("Quotient = $quotient") println("Remainder = $remainder") }
When running this program, the output is:
Quotient = 6 Remainder = 1
In the above program, two numbers25(The dividend) and4(The divisor) is stored in two variables, dividend and divisor.
Now, to find the quotient, we use}} / operator divides dividend by divisor. Since both dividend and divisor are integers, the result will also be calculated as an integer.
Therefore, mathematically25/4The result is6.25but since both operands are int, the variable quotient only stores6(integer part).
Similarly, to find the remainder, we use the % operator. Therefore, the25/4the remainder (i.e.,1stored in the integer variable remainder.
Finally, use the println() function to print the quotient and remainder on the screen.
The equivalent code in Java is: Java withQuotient and Remainder