Java provides multiple ways to display output on the screen. These output methods are mainly used for debugging, displaying results, and user interaction.
System.out.print() prints output without a new lineSystem.out.println() prints output with a new lineSystem.out.printf() prints formatted outputThe System.out object represents the standard output stream connected to the console.
// Using print method
System.out.print("Hello");
System.out.print(" World");
// Using println method
System.out.println("Hello");
System.out.println("World");
// Using printf for formatted output
int age = 20;
System.out.printf("Age is %d years", age);
Output:
Hello World
Hello
World
Age is 20 years
println() for readable outputprintf() for formatted data