0
0
Kotlinprogramming~5 mins

Print and println output in Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the difference between print() and println() in Kotlin?
print() outputs text without moving to a new line, so the next output continues on the same line. println() outputs text and then moves to a new line, so the next output starts on the next line.
Click to reveal answer
beginner
What will be the output of this Kotlin code?<br>
print("Hello")
print("World")
The output will be HelloWorld on the same line because print() does not add a new line after printing.
Click to reveal answer
beginner
What will be the output of this Kotlin code?<br>
println("Hello")
println("World")
The output will be:<br>Hello<br>World<br>Each word is printed on its own line because println() adds a new line after printing.
Click to reveal answer
beginner
Can you use print() and println() together? What happens?
Yes, you can mix them. print() will print text without moving to a new line, and println() will print text and then move to a new line. This lets you control exactly how your output looks.
Click to reveal answer
beginner
How do you print a variable value in Kotlin using println()?
You can print a variable by placing it inside println() using string templates like this:<br>
val name = "Alice"
println("Hello, $name!")
This will output: Hello, Alice!
Click to reveal answer
What does println() do after printing text?
AMoves to a new line
BPrints text without moving to a new line
CDeletes the printed text
DPrints text twice
What will this code print?<br>
print("Hi")
println(" there")
AHi (on one line) and there (on same line)
BHi (on one line) and there (on next line)
CHi there (on one line)
DthereHi
Which function would you use to print text and stay on the same line?
Aprint()
Bprintln()
CreadLine()
DprintlnLine()
What will this code output?<br>
println("A")
print("B")
println("C")
AA (line 1) B (line 1) C (line 2)
BA (line 1) B (line 2) C (line 3)
CABC (line 1)
DA (line 1) BC (line 2)
How do you include a variable inside a string in println()?
AUsing + to join strings
BUsing $variable inside the string
CUsing %variable%
DUsing variable()
Explain the difference between print() and println() in Kotlin and give an example of when to use each.
Think about how output appears on the screen line by line.
You got /4 concepts.
    Describe how you can combine print() and println() to format output in Kotlin.
    Consider how to keep some text on the same line and move to a new line after.
    You got /3 concepts.