Search⌘ K

Printing Styles

Explore different Java printing methods like println, print, and format to control how text appears on the screen. Understand format specifiers such as %s and %d and how they help include variables in printed output, gaining foundational skills in Java programming.

In the last lesson, we used System.out.println to print Hello World! to the screen. There are a couple of other ways to print text on the screen. Let’s take a look at each of them.

System.out.println

You can break the println statement into print and ln (short for line). As apparent from the name, println prints the complete text literal to the screen in the form of a line. The cursor moves to the next line after printing the text.

See an example below.

Java
class Introduction
{
public static void main(String args[])
{
System.out.println("My name is Tracy and I am 17 years old.");
System.out.println("I am learning Java.");
}
}

Notice that after printing the text literal at line 5, the cursor moves to the next line. This is why I am learning Java ...