Java output String variable with syso.printf

huangapple 未分类评论60阅读模式
标题翻译

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.

huangapple
  • 本文由 发表于 2020年3月16日 16:35:04
  • 转载请务必保留本文链接:https://java.coder-hub.com/60702621.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定