0
0
Javaprogramming~5 mins

Output using System.out.print in Java

Choose your learning style9 modes available
Introduction

We use System.out.print to show messages or results on the screen without moving to a new line.

When you want to display a message or value to the user.
When you want to show multiple pieces of information on the same line.
When you want to build a line step-by-step by printing parts one after another.
When you want to keep the cursor on the same line for further output.
Syntax
Java
System.out.print(expression);

The expression can be text in quotes, numbers, or variables.

This method does not add a new line after printing.

Examples
Prints the word Hello without moving to the next line.
Java
System.out.print("Hello");
Prints the number 123 on the screen.
Java
System.out.print(123);
Prints the text Age: 25 on the same line.
Java
System.out.print("Age: " + 25);
Sample Program

This program prints "Hello, " and then "world!" on the same line because System.out.print does not add a new line.

Java
public class Main {
    public static void main(String[] args) {
        System.out.print("Hello, ");
        System.out.print("world!");
    }
}
OutputSuccess
Important Notes

If you want to print and then move to a new line, use System.out.println instead.

You can combine text and variables using the + sign inside System.out.print.

Summary

System.out.print shows output on the screen without moving to a new line.

Use it to print multiple things on the same line.

Remember, it does not add a line break after printing.