Displaying Data
Submitted by jeffheaton on Thu, 01/10/2008 - 03:52
We have seen that there are two different ways to display data to the console window. The following two methods both display data to the console window.
System.out.print System.out.println
But what exactly is the difference between these two methods? First, we will look at what System.out.println does. Consider the following two lines of code.
System.out.println("Hello");
System.out.println("World");
These two lines would produce the following output.
Hello World
Now consider if we were to use print instead of println. Consider the following two lines of code that use print.
System.out.print("Hello");
System.out.print("World");
If you executed the above two lines of code you would get a different output. These two lines of code would produce the following output.
HelloWorld
As you can see, System.out.println moves to a new line. Whereas System.out.print does not move to a new line.




