Kotlin Program to Print an Integer Entered by the User: In this program, you’ll learn to print an integer entered by the user. The integer is stored in a variable and printed to the screen using nextInt() and println() functions respectively.
Kotlin Program to Print an Integer Entered by the User
Source Code
import java.util.Scanner
fun main(args: Array<String>) {
// Creates a reader instance which takes
// input from standard input - keyboard
val reader = Scanner(System.`in`)
print("Enter a number: ")
// nextInt() reads the next integer from the keyboard
var integer:Int = reader.nextInt()
// println() prints the following line to the output screen
println("You entered: $integer")
}
Output
Kotlin Program to Print an Integer Entered by the User