In this post, we will go through Kotlin program to multiply integer and floating point number.
Kotlin Program to Multiply Two Floating Point Numbers
Sourcecode –
import java.util.* fun main() { val read = Scanner(System.`in`) println("Enter Integer number:") val a = read.nextInt() println("Enter floating number:") val b = read.nextFloat() val result = a * b println("Product of $a and $b = $result") }
When you run the program, output will be
Enter Integer number: 10 Enter floating number: 30 Product of 10 and 30.0 = 300.0
Explanation:
Methods/Functions used in this program –
- nextInt(): Used to take Integer integer from standard input – Keyboard
- nextFloat(): Used to take floating point number input from standard input
- println(): User to print output to console.
We have read integer from standard input ( i.e. Keyboard) using nextInt() and stored in variable a
Then, we have read floating point number from standard input ( i.e. Keyboard) using nextFloat() and stored in variable b
Then, we defined another variable result and stored product of two variables a and b.
Finally, result is shown using println()
Thus, we went through Kotlin program to multiply integer and floating point number.