Escape Formatter
In this chapter you will learn:
The %n and %% Specifiers
The %n
and %%
format specifiers escape sequences.
The %n
inserts a newline.
The %%
inserts a percent sign.
You can use the standard escape sequence \n
to embed a newline character.
Here is an example that demonstrates the %n
and %%
format specifiers:
import java.util.Formatter;
//from j a va 2 s . c o m
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:
The following code combines the %n, %d %% to display file copy progress information.
import java.util.Formatter;
// j ava2 s . c o m
public class MainClass {
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:
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » String