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.

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

Practice on your own: Online Java compiler