最适合网络开发者的网站
Kotlin。W3Schools 英文版。初学者课程

尿素 西斯

Kotlin Output (Print Text)


Kotlin Output (Print)

The println() function is used to output values/print text:

例子

fun main() {
  println("Hello World")
}
亲自尝试 »

You can add as many println() functions as you want. Note that it will add a new line for each function:

例子

fun main() {
  println("Hello World!")
  println("I am learning Kotlin.")
  println("It is awesome!")
}
亲自尝试 »

You can also print numbers, and perform mathematical calculations:

例子

fun main() {
  println(3 + 3)
}
亲自尝试 »

The print() function

There is also a print() function, which is similar to println(). The only difference is that it does not insert a new line at the end of the output:

例子

fun main() {
  print("Hello World! ")
  print("I am learning Kotlin. ")
  print("It is awesome!")
}
亲自尝试 »

Note that we have added a space character to create a space between the sentences.