top of page

Java Output – How to Print Text and Numbers

Displaying output is one of the first things every Java programmer learns. Java provides two main methods to show output on the screen:


System.out.println() and System.out.print().


Whether you're printing simple text or performing calculations, these functions are essential in building your coding foundation.


Printing Text with println()

Java uses the System.out.println() method to print text and move the cursor to a new line. For example, you can display a greeting message by typing:

System.out.println("Hello World!");

You can write as many println() statements as you want. Each one will print on a new line:

System.out.println("Hello World!");System.out.println("I am learning Java.");System.out.println("It is awesome!");


Note: Always wrap your text in double quotes. Without them, the code will throw an error.


For example:

Correct:System.out.println("This will work.");

Incorrect:System.out.println(This will show an error);


The print() Method

Unlike println(), the print() method does not jump to a new line after printing the text. It continues printing on the same line.

System.out.print("Hello ");System.out.print("World!");

This will output:Hello World!

Notice how both strings are printed on the same line. We added a space after the first word to ensure readability.

Although print() is useful, we usually prefer println() in tutorials because it's easier to follow the output.


Printing Numbers in Java

Java can also print numeric values using System.out.println() or System.out.print(), without using quotation marks.

For example:

System.out.println(3);System.out.println(358);System.out.println(50000);

You can also perform calculations directly inside the output statement:

System.out.println(3 + 3);System.out.println(2 * 5);

These expressions will be evaluated, and their results will be displayed.


Summary of Java Output Methods

  • Use System.out.println() to print and go to the next line.

  • Use System.out.print() to print on the same line.

  • Always use double quotes for text.

  • Never use quotes for numbers.

  • You can perform arithmetic inside the output method.


Ready to learn more? Explore related Java concepts:

  • Java Syntax

  • Java Comments

  • Java Variables

  • Java Data Types

  • Java Strings

  • Java Operators

  • Java If...Else Statements

  • Java Arrays


Support this free content by donating here:👉 https://razorpay.me/@krishnamohanyagneswaran


Recent Posts

See All

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
  • Youtube
  • alt.text.label.Instagram

©2025 All Rights Reserved.

logo

Resources

bottom of page