(adsbygoogle = window.adsbygoogle || []).push({});
java里常用的控制台输出语句有System.out.println和System.out.print。但是这2者有什么区别了?
最明显的区别就是
System.out.println()输出后追加一个换行 而 System.out.print()输出后不会换行
例如:
代码语言:javascript复制public class ForEachLoop {
public static void main(String[] args){
String[] words = {"Welcome ","to ","myBlog"};
for (String word: words){
System.out.println(word);
}
}
}
输出为:
代码语言:javascript复制Welcome
to
myBlog
代码语言:javascript复制public class ForEachLoop {
public static void main(String[] args){
String[] words = {"Welcome ","to ","myBlog"};
for (String word: words){
System.out.print(word);
}
}
}
输出为:
代码语言:javascript复制Welcome to myBlog