在printf()中设置负宽度吗?

问题描述 投票:0回答:1

例如,如果实际上没有向左移动任何像素,设置负宽度的意义是什么?

System.out.printf("%-9s", "Name:"); //even though I have -9 it doesn't actually move to the left

但是有:

System.out.printf("%9s", "Name:"); //moves Name to the right 9 pixels

那么,如果(-)宽度实际上没有向左移动,它的点是什么?

[Note:

我使用intelliJ,所以也许对我的IDE有用吗?

如果没有实际向左移动像素,设置负宽度的意义是什么,例如:System.out.printf(“%-9s”,“ Name:”); //即使我有-9,它实际上也不会移到...

java printf string-formatting
1个回答
0
投票

设置宽度将为您的输出保留最小数量的空格。它不会左右移动起点。它只是在您指定的宽度的边缘对输出进行右对齐。

© www.soinside.com 2019 - 2024. All rights reserved.