java - Printf 格式问题。不会对齐
问题描述
我在这里查看了一堆关于我的问题的问题,甚至是关于 Java 的问题,但我一直无法弄清楚。这是我的代码
System.out.printf(
"%-20s %-20s %-20s %-20s %-20s %-20s %-20s %-20s %-20s\n",
"Record #",
"Inventory",
"Size", "Color", "Cost", "Markup", "Sale Price", "QTY", "SKU #");
for (int x = 0; x < StoreInventory.inventory.length; ++x) {
System.out.printf(
"%-20s %-20s %-20s %-20s %-20s %-20s %-20s %-20s %-20s\n", x + 1,
StoreInventory.inventory[x][0],
StoreInventory.inventory[x][1],
StoreInventory.inventory[x][2],
StoreInventory.buyPrice[x],
StoreInventory.markUp[x],
StoreInventory.storeSalePrice[x],
StoreInventory.quantity[x],
StoreInventory.skuNumber[x]);
}
输出是:
Record # Inventory Size Color Cost Markup Sale Price QTY SKU #
1 SHORTS XL BLACK 5.0 10.0 50.0 10 SL-1234AE
所有字段都是用户输入。无论输入的大小如何,我需要更改什么来对齐输出?
解决方案
推荐阅读
- c# - 视图性能问题中的计算列
- rust - 为什么双重反转迭代器的行为就好像它从未反转过一样?
- css - 使用 CSS 的变换时图像消失
- android - 在 AsyncTask 中设置 Firebase 存储图像的墙纸
- c# - 如何从 C# 访问另一个应用程序的组合框
- account-kit - Facebook 的 Account Kit 从 iphone X 的最高利润中被切断
- javascript - 将 Braintree 客户端令牌集成到 Braintree.client.create
- c# - 如何选择随机选项?
- javascript - 不使用 jQuery 将复选框与父/子关系链接
- java - Kubernetes集群上tomcat的优雅关闭