Question 12
Back to Exercise
What is the output of the following Java program?
public class Main {
public static void main(String[] args) {
String html = """
<ul>
<li>Java</li>
</ul>
""";
System.out.print(html);
System.out.println(html.lines().count() + " " + html.endsWith("\n"));
}
}
- A <ul> <li>Java</li> </ul> 3 true Correct
- B <ul> <li>Java</li> </ul> 3 true
- C <ul> <li>Java</li> </ul> 3 true
- D <ul> <li>Java</li> </ul> 3 false
Correct Answer: Option A
The common indentation of the lines (and of the closing """) is removed; relative indentation is kept. A closing """ on its own line adds a final newline.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!