The visible difference is simple:
System.out.println()writes its value and then ends the line.System.out.print()writes its value without automatically ending the line.
Using println:
1 | String[] words = {"Welcome", "to", "myBlog"}; |
Output:
1 | Welcome |
Using print with spaces in the output:
1 | for (String word : words) { |
Output:
1 | Welcome to myBlog |
For formatted output, System.out.printf() is often more convenient:
1 | System.out.printf("Name: %s, score: %d%n", name, score); |
%n emits the platform-appropriate line separator.