[英]Java String formatting a line with different variable types
I need to put for example 5 spaces after the first variable 我需要在第一个变量之后放置例如5个空格
2 spaces_go_here 300 batch ordered (due on day 7)
this is the format of the line and it consists of an Integer + Integer + String 这是该行的格式,它由Integer + Integer + String组成
I've tried the following but without success. 我尝试过以下但没有成功。
System.out.printf("%-5d%d%s",i + " " + testProduct.getQuantity() + " batch");
Although printf("%-5s%s",..
works if I'm trying to put spaces in between two Strings 虽然printf("%-5s%s",..
如果我试图在两个字符串之间放置空格
The arguments to the Variadic function PrintStream.printf(String, Object...)
are comma separated, this Variadic函数 PrintStream.printf(String, Object...)
的参数以逗号分隔,这个
System.out.printf("%-5d%d%s",i + " " + testProduct.getQuantity() + " batch");
should be something like 应该是这样的
System.out.printf("%-5d%d%s",i, testProduct.getQuantity()," batch");
Or 要么
System.out.printf("%-5d%d batch",i, testProduct.getQuantity());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.