Java Formatter %n and %% Specifiers

Introduction

The %n and%% format specifiers do not match an argument.

They are escape sequences that insert a character into the output String value.

The %n inserts a newline.

The %% inserts a percent sign.

Here is an example that demonstrates the %n and %% format specifiers:


// Demonstrate the %n and %% format specifiers. 
import java.util.Formatter;

public class Main {
  public static void main(String args[]) {
    Formatter fmt = new Formatter();

    fmt.format("demo2s.com has 1234%n topics, and %d%% of them are complete", 88);
    System.out.println(fmt);/*from   w w  w  .java 2  s. c o  m*/
    fmt.close();
  }
}



PreviousNext

Related