Friday, November 8, 2019

Kotlin Program to Multiply two Floating Point Numbers

In the above program Kotlin Program to Multiply two Floating Point Numbers, we have two floating point numbers 1.5f and 2.0f stored in variables first and second respectively.

Notice, we have used f after the numbers. This ensures the numbers are Float, otherwise they will be assigned - type Double.
Kotlin Program to Multiply two Floating Point Numbers

You can also add :Float after variable name (val first: Float) during declaration, but, unlike Java, Kotlin automatically does that for you so it is not mandatory.
fun main(args: Array<String>) {
    val first = 1.5f
    val second = 2.0f
    val product = first * second
    println("The product is: $product")
}
When you run the program, the output will be:
The product is: 3.0 

No comments:

Post a Comment