Menu
Coddy logo textTech

System.out Methods

Part of the Fundamentals section of Coddy's Java journey — lesson 33 of 73.

In Java, the System.out object provides various methods for printing output to the console. Here are some of the most commonly used System.out methods:

  • print(String s): Prints a string to the console. It does not add a newline character at the end, so subsequent output will continue on the same line.
  • println(String s): Prints a string to the console followed by a newline character. This means the next output will start on a new line.

Here's how you can use these methods:

String name = "Alice";
int age = 30;

System.out.print("Name: ");
System.out.print(name);
System.out.println(" is " + age + " years old.");

System.out.println("Hello, " + name + "!");

This code will produce the following output:

Name: Alice is 30 years old.
Hello, Alice!
challenge icon

Challenge

Beginner

Write a Java program that uses System.out methods to output the following:

  1. Print "Hello, " and "Coddy!" on the same line.
  2. Print "Java is fun!" on a new line using println.

Cheat sheet

Java provides System.out methods for console output:

  • print(): Prints without adding a newline (output continues on same line)
  • println(): Prints and adds a newline (next output starts on new line)
System.out.print("Hello, ");
System.out.print("World");
System.out.println(" - same line");
System.out.println("New line");

Output:

Hello, World - same line
New line

Try it yourself

public class Main {
    public static void main(String[] args) {
        System.out.print("Hello, ");
        // Write your code below

    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals