Kotlin Program to Multiply Integer and Floating Point Number

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 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.

Support Us

If you like Tutorialwing and would like to contribute, you can email an article on any educational topic at tutorialwing@gmail.com. We would love to publish your article. See your article on Tutorialwing and help others with your knowledge. Follow Facebook, LinkedIn, Google+, Twitter, Youtube for latest updates.
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