设置 Java 中的最小字段宽度
字段最小宽度说明符是您在 % 和格式转换代码之间包含的内容。
要在字段宽度说明符之前包含 0,请使用 0 填充。% 标记和格式转换代码之间的整数用作最小字段宽度说明符。
让我们看一个示例 −
示例
import java.util.Formatter;
public class Demo {
public static void main(String args[]) {
Formatter f = new Formatter();
System.out.println(f.format("%08d", 697));
f = new Formatter();
System.out.println(f.format("%10d", 9878));
f = new Formatter();
System.out.println(f.format("%06d", 697));
}
}输出
00000697
9878
000697
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP