LearnFrenzy
Sign in Take a free test

Strings and StringBuilder · Predict the Output · Question 12

Indentation in a text block Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 12 Back to Exercise

What is the output of the following Java program?

Main.java
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links