- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Kotlin Program to Print a String
In this article, we will understand how to print a string. String is a datatype that contains one or more characters and is enclosed in double quotes(“ ”).
Below is a demonstration of the same
Suppose our input is −
Hello my name is John!
The desired output would be
The string is: Hello my name is John!
Algorithm
Step 1 − START
Step 2 − Define a string variable
Step 3 − Display the string on the console
Step 4 − STOP
Example 1
In this example, we will print a string using the print() method in Kotlin. First, declare a string variable, which will be our input string −
val inputStr = "Hello my name is David!"
Now, print the above string using the print() method −
print("The string is defined as: " +inputStr)
Let us now see the complete example
fun main() { val inputStr = "Hello my name is David!" println("The string is defined as: " +inputStr) }
Output
The string is defined as: Hello my name is David!
Example 2
Here, we have created a custom function and printed a string
fun printStr(inputStr : String){ println("The string is defined as: " +inputStr) } fun main() { val inputStr = "Hello my name is John!" printStr(inputStr) }
Output
The string is defined as: Hello my name is John!
- Related Articles
- Kotlin Program to Print an Integer
- Kotlin Program to Print the ASCII values
- Java Program to Print a String
- How to Print a String in Swift Program?
- C program to print string tokens
- Print shortest path to print a string on screen in C Program.
- Java Program to print distinct permutations of a string
- How to print all the elements of a String array in Kotlin in a single line?
- C program to print a string without any quote in the program
- Java Program to Print all unique words of a String
- Python program to print even length words in a string
- Python Program to print all permutations of a given string
- C Program to print all permutations of a given string
- C program to print the ASCII values in a string.
- Java program to print whether the given string is a palindrome

Advertisements