Diving into Java

public class HelloPrinter
{
 public static void main(String[] args)
 {
 System.out.print(3);
 System.out.println("3 + 4 + 5");
 }
}

I wrote my first ever very simple Java program today which executes two lines of instructions and prints the output on a single line.

Lets take a look at lines 5 and 6 of this program.

System.out.print(3); prints the number 3 and positions the cursor immediately to the right of the number 3.

System.out.println(“3 + 4 + 5”);  prints the string 3 + 4 + 5 immediately to the right of the number 3.

If I had used println instead of print, the cursor would have moved to a new line.  Since I used print,  the cursor moved to the right of the number 3 allowing for the output to print on the same line.

The second line of the program prints out  the string 3 + 4 + 5 resulting in combining a number and a string together in a single line of output.

33 + 4 + 5