【发布时间】:2021-12-19 22:10:05
【问题描述】:
我正在寻找格式化此代码:
Object[][] table = new String[4][];
table[0] = new String[] { "Pie", "2.2", "12" };
table[1] = new String[] { "Cracker", "4", "15" };
table[2] = new String[] { "Pop tarts", "1", "4" };
table[3] = new String[] { "Sun Chips", "5", "2" };
String itemId = CommandLine.Help.Ansi.AUTO.string("@|bold,green,underline ItemId|@");
System.out.format("%-15s%-15s%-15s%-15s\n", itemId, "Item", "Price", "Quantity");
for (int i = 0; i < table.length; i++) {
Object[] row = table[i];
System.out.format("%-15d%-15s%-15s%-15s\n", i, row[0], row[1], row[2]);
}
这是早期堆栈交换问题 (java formatting tabular output) 的衍生示例
但是,使用我的标记字符串,而不是正确获取tabbed headers, 我收到的是this。
发生了什么事?
【问题讨论】:
-
图片的链接是否正确? “正确的选项卡标题”链接实际上是不正确的输出吗?
-
哎呀!对,那是正确的。让我编辑帖子。 @吉姆加里森