[英]Combine 2 “System.out.format” statements into 1
How to combine following System.out.format
statements into 1, so that it prints: 如何将以下System.out.format
语句合并为1,以便打印:
1a. Longest string: 'sentence', Size: '8'
My code: 我的代码:
System.out.format("1a. Longest string: '%s'",longestString);
System.out.format(", Size: '%s'%n",tokens.length);
Thank you. 谢谢。
If I understand your question, you could do it like this - 如果我理解您的问题,您可以这样做-
System.out.format("1a. Longest string: '%s', Size: '%s'%n",
longestString, tokens.length);
This is simple: 这很简单:
The format
method goes through the format string, and plugs in the elements of the additional parameter list in places where it sees a format specifier. 该format
方法经过格式字符串,并在地方附加参数列表,它看到的格式说明符的元素插头。 That is why combining the two is a purely mechanical task. 这就是为什么将两者结合在一起纯粹是机械任务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.