Using a New system.out.println() for every line or using + "\n" for every new line?

huangapple go评论57阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年4月9日 09:28:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/61112554.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定