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?✗ Incorrect
println() prints the text and then moves the cursor to the next line.What will this code print?<br>
print("Hi")
println(" there")✗ Incorrect
print("Hi") prints 'Hi' without new line, then println(" there") prints ' there' and moves to new line, so output is 'Hi there' on one line.Which function would you use to print text and stay on the same line?
✗ Incorrect
print() prints text and stays on the same line.What will this code output?<br>
println("A")
print("B")
println("C")✗ Incorrect
println("A") prints A and new line, print("B") prints B on same line, println("C") prints C and new line. So line 1: A, line 2: BC.How do you include a variable inside a string in
println()?✗ Incorrect
Kotlin uses string templates with $variable to include variable values inside strings.
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.