Printf格式问题。不会对齐

时间:2018-04-26 13:12:20

标签: 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     

所有字段均为用户输入。 无论输入的大小如何,我需要更改以对齐输出?

0 个答案:

没有答案