Skip to content

文字块输出问题#10

Open
wxywizard wants to merge 5 commits intoXueleiFan:mainfrom
wxywizard:main
Open

文字块输出问题#10
wxywizard wants to merge 5 commits intoXueleiFan:mainfrom
wxywizard:main

Conversation

@wxywizard
Copy link
Copy Markdown

老师为啥我这两个输出是false?

@jpg1024
Copy link
Copy Markdown
Contributor

jpg1024 commented Nov 23, 2021

        String poetryHtml =
                "<html>\n" +
                "<head></head>\n" +
                "<body>\n" +
                "<div align=\"center\">\n" +
                "    No man is an island,<br />\n" +
                "    Entire of itself,<br />\n" +
                "    Every man is a piece of the continent,<br />\n" +
                "    A part of the main.\n" +
                "</div>\n" +
                "</body>\n" +
                "</html>\n"; /// 此处少了一个换行.
        System.out.println(poetryHtml);
        System.out.println();
        String poetryTextArea = """
                <html>
                <head></head>
                <body>
                <div align="center">
                    No man is an island,<br />
                    Entire of itself,<br />
                    Every man is a piece of the continent,<br />
                    A part of the main.
                </div>
                </body>
                </html>
                """;
        System.out.println(poetryTextArea);
        System.out.println(poetryHtml.equals(poetryTextArea));
        System.out.println(poetryHtml==poetryTextArea);

你的poetryHtml 少了一个换行符.

@jpg1024
Copy link
Copy Markdown
Contributor

jpg1024 commented Nov 23, 2021

另外一种方案:

        String poetryHtml =
                "<html>\n" +
                "<head></head>\n" +
                "<body>\n" +
                "<div align=\"center\">\n" +
                "    No man is an island,<br />\n" +
                "    Entire of itself,<br />\n" +
                "    Every man is a piece of the continent,<br />\n" +
                "    A part of the main.\n" +
                "</div>\n" +
                "</body>\n" +
                "</html>"; 
        System.out.println(poetryHtml);
        System.out.println();
        String poetryTextArea = """
                <html>
                <head></head>
                <body>
                <div align="center">
                    No man is an island,<br />
                    Entire of itself,<br />
                    Every man is a piece of the continent,<br />
                    A part of the main.
                </div>
                </body>
                </html>"""; /// 这个地方结尾改成这样也可以.
        System.out.println(poetryTextArea);
        System.out.println(poetryHtml.equals(poetryTextArea));
        System.out.println(poetryHtml==poetryTextArea);

@wxywizard
Copy link
Copy Markdown
Author

另外一种方案:

        String poetryHtml =
                "<html>\n" +
                "<head></head>\n" +
                "<body>\n" +
                "<div align=\"center\">\n" +
                "    No man is an island,<br />\n" +
                "    Entire of itself,<br />\n" +
                "    Every man is a piece of the continent,<br />\n" +
                "    A part of the main.\n" +
                "</div>\n" +
                "</body>\n" +
                "</html>"; 
        System.out.println(poetryHtml);
        System.out.println();
        String poetryTextArea = """
                <html>
                <head></head>
                <body>
                <div align="center">
                    No man is an island,<br />
                    Entire of itself,<br />
                    Every man is a piece of the continent,<br />
                    A part of the main.
                </div>
                </body>
                </html>"""; /// 这个地方结尾改成这样也可以.
        System.out.println(poetryTextArea);
        System.out.println(poetryHtml.equals(poetryTextArea));
        System.out.println(poetryHtml==poetryTextArea);

thanks

</html>
""";
System.out.println(poetryTextArea);
// 老师为啥我这两个输出是false?
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to remove this comment as it does not apply any longer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants