【发布时间】:2011-02-12 04:36:12
【问题描述】:
我正在使用printf() 在Java 中创建一个输出来创建表头。其中一列需要可变宽度。
基本上应该是这样的:
//two coords
Trial Column Heading
1 (20,30)(30,20)
//three coords
Trial Column Heading
1 (20,40)(50,10)(90,30)
我尝试使用:
int spacing = numCoords * 7; //size of column
printf("Trial %*^s", column, "Column Heading");
但是当我尝试在转换语句中使用* 或^ 时,我不断收到输出错误。
有人知道正确的格式字符串应该是什么吗?
【问题讨论】: