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.
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.
Notice, we have used f after the numbers. This ensures the numbers are Float, otherwise they will be assigned - type Double.
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>) {When you run the program, the output will be:
val first = 1.5f
val second = 2.0f
val product = first * second
println("The product is: $product")
}
The product is: 3.0
No comments:
Post a Comment