Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我想用 n 替换 10(其中 int n=10),我该怎么写:
StdOut.printf("%10s","Hello");
我试着写:
int n=10; StdOut.printf("%ns","Hello");
但这是错误的.. 解决方案是什么?
你试过这个吗: -
System.out.printf("%" + n + "s","Hello");
尝试使用:-
int n=10; StdOut.printf("%" + n + "s","Hello");
你可以试试这段代码:
int n=10; System.out.println("$n$s".replaceAll("$n$", n+""));
这将简单地替换所有值。