> ## Content Index
> Fetch the complete content index at: https://www.ggorantala.dev/llms.txt
> Use this file to discover other available public pages before exploring further.

# Printing To The Console in Java
- URL: https://www.ggorantala.dev/print-to-console/
- Published: 2024-04-04T13:05:49.000Z
- Updated: 2024-04-04T13:05:49.000Z
- Author: Gopi Gorantala
- Tags: Java Articles

## Introduction

Printing something on the console or panel that displays important messages, such as errors, messages, or data outputs, directly for developers.

In Java, you can print to the console using the `System.out.println()` method. Here's a simple example:

```java
System.out.println(100);
```

prints `100` on the console.

Much of the work done by computer is not visible by default, we use something like `System.out.println()` to print if we need some information to be displayed on the console to check for the right data.

Example:

```java
class PrintToConsole {
    public static void main(String[] args) {
        // Printing a simple message to the console
        System.out.println("Hello, world!");

        // Printing values
        System.out.println(100);
        System.out.println(200);

        // Printing multiple lines
        System.out.println("Printing multiple lines:");
        System.out.println("Line 1");
        System.out.println("Line 2");
        System.out.println("Line 3");

        // Printing without a newline character
        System.out.print("This ");
        System.out.print("is ");
        System.out.print("on ");
        System.out.print("the ");
        System.out.print("same ");
        System.out.print("line.");
    }
}

```

The above code prints the following output on the console.

```java
Hello, world!
100
200
Printing multiple lines:
Line 1
Line 2
Line 3
This is on the same line.
```

As you can see `println()` is printing in new line whereas `print()` is just printing on the same line.

## Assignment

Try to print `200` and string `Hello there`.

```java
class Assignment {
  public static void main(String[] args) {
    // print the `Hello there` message.
    // WRITE-CODE HERE

    
  }
}
```

Look at the above examples if you get stuck.

> The answer is `System.out.println("Hello there");`. 

The final code looks like

```java
class Assignment {
  public static void main(String[] args) {
    // print the `Hello there` message.
    // WRITE-CODE HERE
    System.out.println("Hello there");
  }
}
```