标题翻译
Java output String variable with syso.printf
问题
我有一个字符串变量。让它是
String name = "Paul";
我想在 printf 中使用这个字符串。就像
System.out.printf("Name: %(这里放一些文本)\t age: %d", name, age);
能做到吗?如果不能,那我应该使用什么?
顺便说一下,%s 在这里不起作用。
英文翻译
I have a String variable. Let it be
String name = "Paul";
I want to use this String in the printf. Like
System.out.printf("Name: %(some text here)\t age: %d", name, age);
Is it possible to do it? If not then what should I use?
%s doesn't work here btw.
答案1
得分: -1
你可以使用以下内容:
System.out.println("Name: " + name + "\t Age: " + age);
为什么不尝试直接拼接这些内容呢?我是否遗漏了其他要求。
英文翻译
You can use the following:
System.out.println("Name: "+ name+ "\t Age: "+ age);
Why not just try appending these. Is there any other requirement, I am missing.
专注分享java语言的经验与见解,让所有开发者获益!
评论