W3Schools Learner's Blog

W3Schools Programming knowledge summary website



Kotlin Input Output

 In this tutorial you will learn about the Kotlin Input Output and its application with practical example.

Kotlin Input Output

Kotlin Input Output statements are used to read input stream from any standard input device (ex. keyboard) to main memory and to send data stream to any standard output device (ex. monitor).

Koltin Output

In Kotlin, we have println() and print() functions available to send output to the standard output (screen).



The println() and print() outputs the given string as following.

Difference Between println() and print()

The print() function prints the given string, while println() function prints the given string similar like print() function. Then it moves the cursor to the beginning of the next line.

Kotlin Input

Kotlin readline() function is used to read a line of string from standard input device like keyboard.



When you run the program, it will prompt you for input then it will print the given string in screen.



The readLine() function takes any input as a string and convert its to values of other data type (like Int) explicitly.

In Kotlin, if you want input of other data types as input the Scanner object. For that, you need to import Scanner class from Java standard library as following –

Getting Integer Input



Here, the nextInt() method takes integer input from the user then store it in an integer variable. To take Long, Float, double and Boolean input from the user, you can use nextLong()nextFloat()nextDouble() and nextBoolean() methods respectively.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.