top of page
Search
Writer's pictureSiah Peih Wee

Differences in Java Print, Printf and Println

In this article, you will learn the differences between the 3 types of print in Java.


Print vs Println

When you use print(), it will print to the console and the cursor stays at the end of the line.

Lets use _ as the example of the cursor. However if you use println(), it will end the line and the cursor move to the next line.


Example of Print

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

Output of Print

Hello World!Hello World!_

Example of Println

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

Output of Print

Hello World!
Hello World!

This is very useful if you want to do the following

Enter your name: _

or

Enter your name below:
_


Printf

Then what is printf? Well... Its printing to the console with formatting. One useful example will be to format decimals.

There are many other formatting, you may wish to read more

82 views0 comments

Comments


Post: Blog2 Post
bottom of page