Saturday, March 3, 2012

Java Lesson #2: The print and println methods.


If you have not read the previous lessons you can do so by going here.

For this Java lesson I am going to teach you the print and println methods. You may remember that we used println to print out the words "Hello, World!".

The System.out object represents an output device or file, which by default is the monitor screen. We use the println method whenever we want to print something out. Another method we can use with System.out is print.

So we have to ways to print something out but what the difference? Find out by typing up the following program and running it. Remember to save it as Pizza.java
If you need help please see the previous lesson.



So have you figured out what the difference is? During execution if you invoke the println method it advances to the next line after it prints. If you use the print method the next thing that gets printed will be on the same line.


So there you have it. That's today's lesson. Comeback tomorrow to learn about String concatenation.

Thanks for reading this lesson and if you found it helpful please help me out and pass this information along. If you haven't signed up to get these lessons emailed to you, sign up over there --->

No comments:

Post a Comment