请问一下java格式化输出明明参数是固定的,为什么循环打印还是对不齐,sos

如图,不太懂为什么,求解答

    for (Entry<String, ProductBase> entry : orderList.entrySet()) {
            System.out.println(String.format("%15s", entry.getValue().productName)
                    +String.format("%10s", "$"+entry.getValue().productPrice)
                    +String.format("%10s", entry.getValue().orderAmount)
                    +String.format("%10s","$"+(double)entry.getValue().orderAmount*(double)entry.getValue().productPrice)
                    +String.format("%30s", entry.getValue().getSellTime()));
        }

img

加个Tab键

每行的第一个值长短不一导致的

因为商品名长度不一致啊

用 System.out.printf() 试试