HOME HTML EDITOR C JAVA PHP

Java Output Methods

In Java, output means displaying data on the screen. Java provides different methods to print output.

1. System.out.print()

The print() method prints text without moving to the next line.

public class Main { public static void main(String[] args) { System.out.print("Hello "); System.out.print("World"); } }

Output: Hello World

2. System.out.println()

The println() method prints text and moves the cursor to the next line.

public class Main { public static void main(String[] args) { System.out.println("Hello"); System.out.println("World"); } }

Output:

Hello World

3. System.out.printf()

The printf() method is used to print formatted output.

public class Main { public static void main(String[] args) { int age = 20; System.out.printf("My age is %d", age); } }

Output: My age is 20

Common Format Specifiers

Summary