英文:
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.
专注分享java语言的经验与见解,让所有开发者获益!
评论