Java Output

Print Text

Java Output / Print

As you recall from the previous chapter, the println() function in Java allows you to produce text or values:

Example

				
					System.out.println("Hello World!");
				
			

You are able to add an unlimited number of println() methods. It should be noted that every procedure will create a new line:

Example

				
					System.out.println("Hello World!");
System.out.println("I am learning Java.");
System.out.println("It is awesome!");
				
			

Double Quotes

When working with text, it needs to be encircled by double quote marks ” “.

An error happens if the double quotes are forgotten:

Example

				
					System.out.println("This sentence will work!");
				
			
				
					System.out.println(This sentence will produce an error);
				
			

The Print() Method

A print() method that is comparable to println() is also available.

The sole distinction is that the output ends without a new line being inserted:

Example

				
					System.out.print("Hello World! ");
System.out.print("I will print on the same line.");
				
			

Take note that in the sample above, we have included an extra space (after “Hello World!”) for easier reading.

We will only use println() in this lesson because it makes code output easier to read.

Share this Doc

Print Text

Or copy link

Explore Topic