From a quick google:

There is also one specifier that doesn't correspond to an argument. It is "%n" which outputs a line break. A "\n" can also be used in some cases, but since "%n" always outputs the correct platform-specific line separator, it is portable across platforms whereas"\n" is not.

Please refer https://docs.oracle.com/javase/tutorial/java/data/numberformat.html

Original source

Answer from Bill K on Stack Overflow
🌐
W3Schools
w3schools.com › java › ref_output_printf.asp
Java Output printf() Method
A . followed by a whole number indicating how many decimal digits to show in the formatted data. conversion - Required. A character which indicates how an argument's data should be represented. If the character is uppercase the data will be formatted in uppercase where possible. The list of possible characters is shown in the table below. ... // Default System.out.printf("%f%n", 123456.78); // Two decimal digits System.out.printf("%.2f%n", 123456.78); // No decimal digits System.out.printf("%.0f%n", 123456.78); // No decimal digits but keep the decimal point System.out.printf("%#.0f%n", 123456.78); // Group digits System.out.printf("%,.2f%n", 123456.78); // Scientific notation with two digits of precision System.out.printf("%.2e", 123456.78);
🌐
Oracle
docs.oracle.com › javase › tutorial › java › data › numberformat.html
Formatting Numeric Print Output (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)
There are many converters, flags, and specifiers, which are documented in java.util.Formatter ... The %d specifies that the single variable is a decimal integer. The %n is a platform-independent newline character. The output is: ... The printf and format methods are overloaded.
🌐
Baeldung
baeldung.com › home › java › core java › formatting output with printf() in java
Formatting Output with printf() in Java | Baeldung
January 8, 2024 - L, N represent the time in milliseconds and nanoseconds accordingly. ... However, listing date multiple times is a pain. Alternatively, to get rid of multiple arguments, we can use the index reference of our input parameter, which is 1$ in our case: System.out.printf("%1$tH:%1$tM:%1$tS %1$tp %1$tL %1$tN %1$tz %n", date);
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › How-to-use-Java-printf-to-format-output
Format output with Java printf
Be sure to remove any commas in the specifier, as attempting to add thousandths groupings for scientific notation will result in a FormatFlagsConversionMismatchException. The following image demonstrates the use of various flags, precision settings and width specifiers to create a table containing advance formatting of doubles with printf. Here’s the code and output of a table of Java double printf examples.
🌐
CodeGym
codegym.cc › java blog › strings in java › printf() in java
Printf() in Java
December 23, 2024 - The Java printf() method, also known as the "format specifier," is used to format text and variables for output. This tool can be used to create informative strings of text without using String concatenation, or relying on non-standard characters ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-printf-method
Java printf() - Print Formatted String to Console | DigitalOcean
August 3, 2022 - Let’s look at the available format specifiers available for printf: ... Note: %n or \n are used as line separators in printf().
Find elsewhere
🌐
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) { // 1. Integer int x = 42; System.out.printf("1.
🌐
Learning Glue
learningglue.com › home › courses › java essentials
Java printf() method - Learning Glue
April 11, 2024 - This printf() method option contains one or more format specifiers typically followed by the arguments to be formatted. We have already met one format specifier, the %n, which will insert a new line and does not require an argument.
🌐
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 - The Java System.out.printf() method formats and outputs a string. You specify the data and the format of the output. The examples below demonstrate different ways to use printf() to format output.
🌐
Codecademy
codecademy.com › docs › java › output › .printf()
Java | Output | .printf() | Codecademy
May 29, 2025 - The .printf() method prints output to the console with the use of various formatting commands. It comes from the PrintStream class and can be used to format strings, numbers, and other data types neatly and precisely.
🌐
xperti
xperti.io › home › formatting with printf() in java
Guide To Use The Java printf() Method For Formatting
May 17, 2022 - Lastly, you can also limit the ... ... The Java printf method can be used to format all types of integers available in Java which includes, byte, short, int, long, and BigInteger with the use of %d specifier....
🌐
Colorado State University
cs.colostate.edu › ~cs160 › .Summer16 › resources › Java_printf_method_quick_reference.pdf pdf
Java printf( ) Method Quick Reference
The course will adopt a problem solving focus with an integrated view of the computer. For programming, the course covers the basic Java syntax and language features, compilation, interpretation, execution, primitive data types, class and object usage, parameter passing, flow of control constructs ...
🌐
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 - Below are some of the commonly ... integer etc., NOTE: In Java’s printf() method, %n is a format specifier representing a platform-independent newline character and is similar to \n in C and C++....
🌐
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 · In order to simplify the formatting process, Java allows programmers to make use of certain keywords to format different data types.
🌐
GeeksforGeeks
geeksforgeeks.org › java › formatted-output-in-java
Formatted Output in Java using printf() - GeeksforGeeks
August 16, 2024 - Decimal Number Formatting can be done using print() and format specifier %f . ... // Java Programs to demonstrate // Use of Printf() for decimal // Number Formatting import java.io.*; // Driver Class class GFG { // main function public static ...
🌐
How to do in Java
howtodoinjava.com › home › java basics › format output with java printf
Format Output with Java Printf
February 23, 2023 - System.out.printf("%tT %n", today); //Prints '22:37:15' System.out.printf("%tF %n", today); //Prints '2022-09-13' System.out.printf("%tc %n", today); //Prints 'Tue Sep 13 22:43:17 IST 2022' This Java tutorial taught us to print formatted output in Java using the format() and printf() methods.
🌐
Medium
sithara-wanigasooriya.medium.com › mastering-output-formatting-in-java-using-printf-78b2255ad6ef
Mastering Output Formatting in Java Using printf | by Sithara Wanigasooriya | Medium
September 20, 2024 - Java’s printf method is a powerful tool for formatting output, allowing you to control the presentation of your data in a precise and…
🌐
Gettysburg College
cs.gettysburg.edu › ~tneller › cs111 › Java_printf_method_quick_reference.pdf pdf
Java printf( ) Method Quick Reference
Numbers are rounded ... A hashcode is like an address. This is useful for printing a reference ... You can build a formatted String and assign it to a variable using the static format method in the String class. The use of a format string and argument list is identical to its use in the printf method.