for(Item i : itemArray){
System.out.format("%1s%50s%50s", "name = " + i.getName(), "color = " + i.getColor(), "quantity = " + i.getQuantity());
System.out.println();
我试图迭代一个项目数组,打印出格式化表格中的每个项目。每件商品都有名称、颜色、数量和价格。
以下是它目前的结果:
Name: bike Color: black Quantity: 1 Price: 6.00
Name: ladder Color: blue Quantity: 150 Price: 9.00
Name: dolphin Color: orange Quantity: 15 Price: 100000.00
Name: key Color: red Quantity: 12 Price: 510.00
这是我需要的样子:
Name: bike Color: black Quantity: 1 Price: 6.00
Name: ladder Color: blue Quantity: 150 Price: 9.00
Name: dolphin Color: orange Quantity: 15 Price: 100000.00
Name: key Color: red Quantity: 12 Price: 510.00
我已经阅读了格式api,但仍然无法弄清楚!请帮忙。