Greetings!
We have recently published 100+ articles on android tutorials with kotlin and java. If you need, you may visit Android Tutorial for beginners page. You can also check Kotlin Tutorial for beginners. Also, if you are interested in content writing, you can mail us at tutorialwing@gmail.com. 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.