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?
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?
println("Hello")
println("World")
The output will be: Hello World 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:
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
✗ Incorrect
println() prints the text and then moves the cursor to the next line.
What will this code print?
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
✗ 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?
Aprint()
Bprintln()
CreadLine()
DprintlnLine()
✗ Incorrect
print() prints text and stays on the same line.
What will this code output?
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)
✗ 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()?
AUsing + to join strings
BUsing $variable inside the string
CUsing %variable%
DUsing variable()
✗ 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.
Practice
(1/5)
1. What is the main difference between print and println in Kotlin?
easy
A. print outputs only numbers; println outputs only text.
B. print adds a newline after output; println outputs text without a newline.
C. print outputs text without a newline; println adds a newline after output.
D. print is used for debugging; println is used for user messages.
Solution
Step 1: Understand print behavior
print outputs text exactly as given and stays on the same line.
Step 2: Understand println behavior
println outputs text and then moves the cursor to the next line.
Final Answer:
print outputs text without a newline; println adds a newline after output. -> Option C
Quick Check:
print no newline, println newline = A [OK]
Hint: Remember: println adds a line break, print does not [OK]
Common Mistakes:
Confusing which function adds a newline
Thinking print adds a newline
Assuming println outputs only numbers
2. Which of the following is the correct syntax to print "Hello" and then move to a new line in Kotlin?
easy
A. println("Hello")
B. print("Hello")
C. println Hello
D. println["Hello"]
Solution
Step 1: Check syntax correctness
Only println("Hello") uses correct function call syntax with parentheses and quotes.
Step 2: Verify output behavior
println("Hello") prints "Hello" and moves to a new line automatically.
Final Answer:
println("Hello") -> Option A
Quick Check:
Correct syntax with println = A [OK]
Hint: Use parentheses and quotes exactly for print/println [OK]
Common Mistakes:
Missing parentheses around arguments
Using square brackets instead of parentheses
Omitting quotes around strings
3. What will be the output of the following Kotlin code?
print("Hi")
println(" there")
print("Welcome")
medium
A. Hi there
Welcome
B. Hi
there
Welcome
C. Hi there Welcome
D. Hi there
Welcome
Solution
Step 1: Trace first print statement
print("Hi") outputs "Hi" without newline.
Step 2: Trace println statement
println(" there") outputs " there" and moves to next line.
Step 3: Trace last print statement
print("Welcome") outputs "Welcome" on the new line.
Final Answer:
Hi there
Welcome -> Option D
Quick Check:
print no newline, println newline = D [OK]
Hint: Remember print stays on line; println moves to next line [OK]
Common Mistakes:
Assuming print adds newline
Ignoring space in " there"
Thinking all output is on one line
4. Identify the error in this Kotlin code snippet:
print("Hello")
println "World"
medium
A. Missing parentheses in println call
B. Missing quotes around Hello
C. print cannot be used without println
D. No error, code runs fine
Solution
Step 1: Check syntax of print statement
print("Hello") is correct with parentheses and quotes.
Step 2: Check syntax of println statement
println "World" is missing parentheses around the argument, which is required in Kotlin.
Final Answer:
Missing parentheses in println call -> Option A
Quick Check:
Function calls need parentheses = B [OK]
Hint: Always use parentheses for function calls in Kotlin [OK]
Common Mistakes:
Omitting parentheses in function calls
Thinking print needs println to work
Confusing quotes usage
5. You want to print the numbers 1, 2, and 3 on the same line separated by spaces, then print "Done" on the next line. Which Kotlin code achieves this?
hard
A. print("1 2 3")
print("Done")
B. print("1 2 3")
println("Done")
C. print("1 ")
print("2 ")
print("3\n")
println("Done")
D. println("1")
println("2")
println("3")
print("Done")
Solution
Step 1: Print numbers on same line with spaces
Using print("1 2 3") outputs "1 2 3" on the same line.
Step 2: Print "Done" on next line
println("Done") prints "Done" and moves to the next line.
Final Answer:
print("1 2 3")
println("Done") -> Option B
Quick Check:
Use print for same line, println for new line = A [OK]
Hint: Use print for same line, println to move to next line [OK]
Common Mistakes:
Using println for each number causing new lines
Using print after println without newline
Adding \n inside print incorrectly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.