英文:
Using a New system.out.println() for every line or using + "\n" for every new line?
问题
以下是要翻译的内容:
我是一名Java初级开发者,我想知道打印多行代码的首选或更好的方法是什么:
System.out.println("Hello world!");
System.out.println("I am a junior Developer");
还是
System.out.println("Hello world" + "\n" + "I am a junior Developer");
英文:
I am a junior Developer in Java and I'd like to know what is the preferred or better way to print multiple lines of code:
System.out.println("Hello world!");
System.out.println("I am a junior Developer");
or
System.out.println("Hello world" + "\n"```
+ "I am a junior Developer");```
答案1
得分: 3
Prefer the first, "\n"
is not the correct sequence for newline on Windows. You could use
System.out.println("Hello world" + System.lineSeparator()
+ "I am a junior Developer");
which potentially avoids an extra (implicit) flush()
but standard io is generally slow anyway.
英文:
Prefer the first, "\n"
is not the correct sequence for newline on Windows. You could use
System.out.println("Hello world" + System.lineSeparator()
+ "I am a junior Developer");
which potentially avoids an extra (implicit) flush()
but standard io is generally slow anyway.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论