我目前正在使用Python,我喜欢能够将变量插入字符串而无需执行
的方式"+ var +"或
" ", var, " "
例子:"我们可以在{}pm出去,然后去{}."。format(5, "Bob's Burgers");
有一种方法可以做到这一点与Java?
是。你可以写
String s = String.format("We can just go out at %d pm and go to %s.", 5, "Bob's Burgers");
使用"System.out. "和占位符,如%d, %s
public class HelloWorld {
public static void main(String[] args) {
String a ="Hello";
String b = "World";
System.out.printf("%s %s",a,b);
}
}