【发布时间】:2020-03-16 08:35:04
【问题描述】:
我有一个字符串变量。就这样吧
String name = "Paul";
我想在 printf 中使用这个字符串。喜欢
System.out.printf("Name: %(some text here)\t age: %d", name, age);
有可能吗?如果没有,那么我应该使用什么? %s 在这里不起作用。
【问题讨论】:
-
为什么不使用 String.format("Name: %s \t age: ...."); ?
-
"%s 在这里不起作用。" Yes it does.
-
System.out.printf() (我相信)只是 String.Format 的包装器。如果你真的使用了 %s 它应该可以工作(而不是“%(some text here)”
-
尝试带上整个代码。 %s 应该可以工作。