In Kotlin, printing an integer is a straightforward task. We can use the println() function to print the integer on the console.
Here’s how to write a Kotlin program to print an integer:
fun main() { val number = 10 println(number) }
In the above program, we have created a variable named number and assigned it a value of 10. Then, we have used the println() function to print the value of number on the console.
The output of the above program will be:
10
In case, you want to print a message along with the integer, you can use string concatenation. Here’s how:
fun main() { val number = 10 println("The number is: " + number) }
In the above program, we have used string concatenation to print a message along with the integer.
We have concatenated the message “The number is: ” with the value of number using the + operator.
The output of the above program will be:
The number is: 10
That’s all there is to printing an integer in Kotlin. With these few lines of code, you can easily print any integer on the console.