How to use %n and %% specifiers to escape new line and percentage?

The %n and %% format specifiers escape sequences. The %n inserts a newline. The %% inserts a percent sign.

You can use the standard escape sequence 

to embed a newline character. Here is an example that demonstrates the %n and %% format specifiers:

import java.util.Formatter;

public class Main {

  public static void main(String args[]) {

    Formatter fmt = new Formatter();

    fmt.format("line%nline %d%% complete", 88);

    System.out.println(fmt);

  }

}

The output:

Copying file

Transfer is 88% complete

The following code combines the %n, %d %% to display file copy progress information.

import java.util.Formatter;
public class Main {
public static void main(String args[]) {
Formatter fmt = new Formatter();
fmt.format(“Copying file%nTransfer is %d%% complete”, 88);
System.out.println(fmt);

}
}
The output:
Copying file
Transfer is 88% complete