OutputEasy2 marks
System.out.print("BEST "); System.out.println("OF LUCK"); Choose the correct option for the output of the above statements: (i) BEST OF LUCK (ii) BEST OF LUCK
Topic: print() and println()
Previous-year question practice database
Answer
Exam answer
(i) BEST OF LUCK
Explanation
print() writes its text and leaves the cursor on the SAME line, while println() writes its text and then moves to a new line. So the first statement leaves the cursor just after "BEST " (note the trailing space inside the quotes), and the second continues on the same line with "OF LUCK". The line break produced by println() comes only AFTER its own text, which is why it does not separate the two. The rule to carry away: it is the FIRST statement that decides whether the two appear on one line.
More from Revision Tour I
The full form of JVM is:2026Which of the following occupies 2 bytes of storage?2026In a statement c = c + (x * d + e); which variable is an accumulator?2026Assertion (A): The result of the Java expression 3 + 7/2 is 6.
Reason (R): According to the hierarchy of operators in Java, addition is done first followed by division.2026Evaluate the Java expression:
x = a * b % (++c) + (++a) + (--b);
if a = 7, b = 8, c = 22026System.out.println('Z' + 32); will display:2025