Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Printing Output | Getting Started
Introduction to Java
Section 1. Chapter 4
single

single

Printing Output

Swipe to show menu

Java provides two main ways to display output on the screen: print() and println(). While both are used to print text, the key difference is how they handle moving to a new line.

The most commonly used method is System.out.println(). It prints the text and automatically moves the cursor to the next line. This makes the output clean and easy to read, especially when printing multiple lines.

Main.java

Main.java

12345678
package com.example; public class Main { public static void main(String[] args) { System.out.println("Hello"); System.out.println("World"); } }

On the other hand, System.out.print() prints text but does not move to a new line. Instead, everything continues on the same line.

Main.java

Main.java

12345678
package com.example; public class Main { public static void main(String[] args) { System.out.print("Hello "); System.out.print("World"); } }

This difference becomes very important when you start controlling how your output is formatted. In most beginner cases, println() is preferred because it automatically organizes output in a readable way.

Task

Swipe to start coding

Replace the line //replace this line with your code with the code that will display Hello World! on the screen.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 4
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt