Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

Learn kotlin Output


Sure! In Kotlin, you can output information to the console using the println() function. This function is used to print text or values to the standard output, which is typically the console or terminal where your program is running. Here's how you can use it:

Printing Text

You can print text directly by passing it as an argument to the println() function.

Example

fun main() {
println("Hello, Kotlin!") // Output: Hello, Kotlin!
}

Printing Variables

You can also print the values of variables by including them within the println() function preceded by a dollar sign $.

Example

fun main() {
val name = "Alice"
val age = 30
println("Name: $name, Age: $age") // Output: Name: Alice, Age: 30
}

Formatting Output

You can format the output using string templates or concatenation.

Example

fun main() {
val apples = 5
val oranges = 3
println("I have $apples apples and $oranges oranges.") // Output: I have 5 apples and 3 oranges.
}

Special Characters

You can also include special characters like newline \n or tab \t in your output.

Example

fun main() {
println("Line 1\nLine 2") // Output: Line 1
// Line 2
println("Column 1\tColumn 2") // Output: Column 1 Column 2
}

Conclusion

The println() function in Kotlin is a simple and effective way to output information to the console. You can print text, variables, format output, and include special characters as needed to make your output more informative and readable.



Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java