Here a few examples:

(The output is shown within double quotes in the embedded comment)

Note : System.out.format() = System.out.printf()

import java.util.Calendar;
import java.util.Locale;

public class TestFormat {

    public static void main(String[] args) {
      long n = 461012;
      System.out.format("%d%n", n);      //  -->  "461012"
      System.out.format("%08d%n", n);    //  -->  "00461012"
      System.out.format("%+8d%n", n);    //  -->  " +461012"
      System.out.format("%,8d%n", n);    // -->  " 461,012"
      System.out.format("%+,8d%n%n", n); //  -->  "+461,012"

      double pi = Math.PI;

      System.out.format("%f%n", pi);       // -->  "3.141593"
      System.out.format("%.3f%n", pi);     // -->  "3.142"
      System.out.format("%10.3f%n", pi);   // -->  "     3.142"
      System.out.format("%-10.3f%n", pi);  // -->  "3.142"
      System.out.format(Locale.FRANCE,
                        "%-10.4f%n%n", pi); // -->  "3,1416"

      Calendar c = Calendar.getInstance();
      System.out.format("%tB %te, %tY%n", c, c, c); // -->  "May 29, 2006"

      System.out.format("%tl:%tM %tp%n", c, c, c);  // -->  "2:34 am"

      System.out.format("%tD%n", c);    // -->  "05/29/06"
    }
}

(source)

Answer from DeMarco on Stack Overflow
🌐
W3Schools
w3schools.com › java › ref_output_printf.asp
Java Output printf() Method
Java Examples Java Videos Java ... The %s character is a placeholder for the string "World": System.out.printf("Hello %s!", "World"); Try it Yourself » ·...
🌐
Medium
medium.com › @kalpana.p_65621 › system-out-printf-in-java-a23690d66f97
System.out.printf() in JAVA. In Java 5.0 and higher versions, the… | by Kalpana P | Medium
January 30, 2025 - An example Java program using format specifiers · Output: Press enter or click to view image in full size · Conclusion: Similar to printf() statement in C, we can use System.out.printf() for the formatted output in JAVA and it is applicable from Java 5.0. 26 followers ·
Discussions

java - how do I use System.out.printf? - Stack Overflow
My teacher wants us to display our values in the format method (at the very bottom) but the problem is we had a sub and she didn't show us how to use it and my teacher is being less than helpful. Any More on stackoverflow.com
🌐 stackoverflow.com
java - How to use System.out.printf - Stack Overflow
1) show your errors. 2) printf has ways to deal with dates. Please check out the java.util.Formatter API for the details. More on stackoverflow.com
🌐 stackoverflow.com
March 20, 2017
Trying to understand System.out.printf
http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html http://docs.oracle.com/javase/7/docs/api/java/io/PrintStream.html#printf%28java.lang.String,%20java.lang.Object...%29 More on reddit.com
🌐 r/java
9
0
October 23, 2013
System.out.printf or System.out.println
Evan Hayes is having issues with: I have done a couple of videos and notice that they use the printf method a lot but the println works the same way is it a problem that i use th... More on teamtreehouse.com
🌐 teamtreehouse.com
2
March 15, 2018
🌐
Medium
naveenautomationlabs.medium.com › mastering-system-out-printf-in-java-dcab1af7dd27
Mastering System.out.printf() in Java | by Naveen AutomationLabs | Medium
April 26, 2025 - System.out.println("Table:"); for (int i = 1; i <= 5; i++) { System.out.printf(" %d squared is %d%n", i, i * i); } ... package JavaInterviewQuestions; import java.util.Date; public class PrintFExamples { public static void main(String[] args) ...
🌐
Oracle
docs.oracle.com › javase › tutorial › java › data › numberformat.html
Formatting Numeric Print Output (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)
The java.io package includes a PrintStream class that has two formatting methods that you can use to replace print and println. These methods, format and printf, are equivalent to one another. The familiar System.out that you have been using happens to be a PrintStream object, so you can invoke PrintStream methods on System.out. Thus, you can use format or printf anywhere in your code where you have previously been using print or println. For example...
🌐
Baeldung
baeldung.com › home › java › core java › formatting output with printf() in java
Formatting Output with printf() in Java | Baeldung
January 8, 2024 - Let’s look at a quick example before we dive into the details of the various formatting rules: System.out.printf("Hello %s!%n", "World"); This produces the following output: Hello World!
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › How-to-use-Java-printf-to-format-output
Format output with Java printf
*/ public static void main(String[] args) { double top = 1234.12345; float bottom = 1234.12345f; System.out.printf("%+,.3f :: %,.5f", top, bottom); /* Example prints: +1,234.123 :: 1234.12345 */ } }
Find elsewhere
🌐
Educative
educative.io › answers › how-to-use-the-printf-function-in-java
How to use the printf() function in Java
Date data = new Date(); System.out.printf(Locale.FRANCE, "Printing current data and time: %tc", data); Object - the object(s) to be printed on the screen · String - the string being passed to the function contains the conversion characters ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-printf-method
Java printf() - Print Formatted String to Console | DigitalOcean
August 3, 2022 - flags can be set as + for right-aligning, and - for left-aligning. Next, fire up your Jshell and start using printf()! ... | Welcome to JShell -- Version 12.0.1 | For an introduction type: /help intro jshell> int x = 10 x ==> 10 jshell> System.out.printf("Formatted output is: %d %d%n", x, -x) ...
🌐
Codecademy
codecademy.com › docs › java › output › .printf()
Java | Output | .printf() | Codecademy
May 29, 2025 - Beginner Friendly.Beginner Friendly17 hours17 hours · System.out.printf(formatString, arg1, arg2, ..., argN); Parameters: formatString: A string containing various format commands defining how to print an arbitrary number of additional arguments.
🌐
DEV Community
dev.to › realedwintorres › how-to-formatting-java-output-with-printf-1bik
How-To: Formatting Java Output With printf() - DEV Community
November 7, 2021 - This example outputs three colors, separated by a comma and a space: ... public class Example { public static void main(String[] args) { String c1 = "red"; String c2 = "orange"; String c3 = "yellow"; System.out.printf("%s, %s, %s\n", c1, c2, c3); } }
🌐
Study.com
study.com › computer science courses › computer science 109: introduction to programming
Using the printf Method for Standard Output in Java | Study.com
If you are using standard out, PrintStream helps format the output. Like other programming languages, in Java you can use the printf method using System.out.printf for formatting the output of numbers and strings. The method takes the format string as the first parameter followed by a list of arguments that are to be formatted.
🌐
CodeGym
codegym.cc › java blog › strings in java › printf() in java
Printf() in Java
December 23, 2024 - Now let’s have another Java printf ... String name = "Alice"; int age = 15; //printf example System.out.printf("Hello, my name is %s and I am %d years old.", name, age); } } The output of the program is here:...
🌐
Codingtag
codingtag.com › system-out-printf-in-java
System.out.printf in Java
System.out.printf("|s|%n", "Java"); // Right-aligned System.out.printf("|%-10s|%n", "Java"); // Left-aligned Output:
🌐
Colorado State University
cs.colostate.edu › ~cs160 › .Spring16 › resources › Java_printf_method_quick_reference.pdf pdf
Colostate
CS 160 Foundations in Programming · Spring 2016 Computer Science Department CS 160 Homepage
Top answer
1 of 2
12
println is used when you want to create a new line with just simple text or even text containing concatenation. ("Hello " + "World" = "Hello World.") printf is used when you want to format your string. This will clean up any concatenation. For a simple example -> ("Hello, " + username + "! How are you?") could easily be cleaned up a bit by using ("Hello, %s! How are you?", username). It's up to you really when you want to use this. I would definitely recommend it if you are using multiple variables. In that case you would use multiple conversions in your string. Please feel free to read up on the Formatter Documentation (https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html) as it will help you understand it better and it provides a full list of available conversion characters.
2 of 2
0
as told by some guy on stack overflow: println() prints a new blank line and then your message. printf() provides string formatting similar to the printf function in C. printf() is primarily needed when you need to print big strings to avoid string concatenaion in println() which can be confusing at times. (Although both can be used in almost all cases). Eg. int a = 10;int b = 20; println("a: " + a + " b: " + b); //Tedious String Concatenation printf("a: %d b: %d\n", a, b); // Output using string formatting. While printf() enables you to print fractional outputs up to any decimal place in a single line, the same task using println() can get very complex. Eg. printf("%.6f",x); // prints x up to 6 decimal places. hope this helps