Java Output

The Java user output statement helps us print the output/result on screen.

Java output statements:

System.out.print()

System.out.println()

System.out.printf()

System.out is the standard output stream used to produce the output of a program on computer screen.

print(), println() and printf() methods help us to print values or output on the screen.

print()

The print() method prints everything on the same line of the screen as shown in below output. After printing output cursor remains in same line.

In below example we used print() statement to print everything in same line.

println()

The println() method prints everything on the next line of the screen as shown in below output. After printing output cursor moves to the next line.

In below example we used println() method to print everything in next line.

print() and println() can perform mathematical calculations and string concatenation.

printf()

The printf() method help us to print formatted String to the console. 

Below are the overloaded printf() methods:

System.out.printf(string);
System.out.printf(format, arguments);

Example:

There are three import thing we need to understand in below sample printf() example:

%n → This is getting used for moving cursor in next line.

%s → It will simply print the given output in small letters.

%S → It will simply print the given output in capital letters.

%s%n → It will simply print the given output in small letters and move the cursor to next line.

%S%n → It will simply print the given output in capital letters and move the cursor to next line.

Imran Khan

Specialist Master (Architect) with a passion for cutting-edge technologies like AEM (Adobe Experience Manager) and a proven track record of delivering high-quality software solutions.

  • Languages: Java, Python
  • Frameworks: J2EE, Spring, Struts 2.0, Hibernate
  • Web Technologies: React, HTML, CSS
  • Analytics: Adobe Analytics
  • Tools & Technologies: IntelliJ, JIRA

🌐 LinkedIn

📝 Blogs

📧 Imran Khan