java printf 需要帮助
public class Format
{
public static void main(String args[])
{
System.out.printf("%30s|%30s","Organization","Number of users");
System.out.printf("%30s|%30s","Arcot","100");
}
}
它打印:
Organization| Number of users Arcot| 100
为什么第二行没有对齐?尽管单词“100”有足够的填充,但单词“Arcot”没有提供足够的填充。抱歉,此文本窗口应用其自己的格式,它没有显示我粘贴为输出的内容。您可能需要运行代码才能查看获得的输出。
public class Format
{
public static void main(String args[])
{
System.out.printf("%30s|%30s","Organization","Number of users");
System.out.printf("%30s|%30s","Arcot","100");
}
}
It prints:
Organization| Number of users Arcot| 100
Why is the 2nd row out of alignment? The word "Arcot" is not given enough padding, although the word "100" is. I'm sorry, this text window applies its own formatting, it is not showing what I have pasted as the output. You may need to run the code to see the output obtained.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这些。
Try these.
您必须在
printf
的第一个参数末尾插入\n
发出换行符。有关使用转义字符的详细信息。
You have to insert
\n
issue a newline character end of first parameter ofprintf
.More info about using escape character.
这按预期工作:
产生结果
在我的机器上 。您没有添加换行符。
%n
是格式字符串中的首选表示法。This works as expected:
results in
on my machine. You didn't add line feeds.
%n
is the preferred notation in format Strings.