Java Tutorial
🔍
Java ProgramsBasics & I/OPrint Multiple Lines

Print Multiple Lines in Java

beginner·  Basics & I/O  ·  Fundamentals

Problem

Each call to System.out.println() automatically adds a newline after the text it prints, so multiple calls appear on separate lines.

Print three separate lines of text to the console.

Input
Output
Line 1 Line 2 Line 3

Java Program

Java
public class PrintMultipleLines { public static void main(String[] args) { System.out.println("Line 1"); System.out.println("Line 2"); System.out.println("Line 3"); // each call starts on a fresh line } }

Output

Line 1 Line 2 Line 3

Core Logic

Calling println() once per line is the most direct way to print several lines — each call ends with its own newline.

How It Works
  1. 1The first println("Line 1") prints the text and moves the cursor to a new line.
  2. 2The next println() call starts writing from that new line, and does the same again.
  3. 3Repeating the call for each line builds up the full multi-line output.
Three separate println() calls produce three separate lines in the console, in the order they were called.
💡

Key Point: print() (without ln) would leave the cursor on the same line — the "ln" in println is what adds the newline automatically.

Key Concepts

System.out.println()newline

Related Programs