K
K
kokapuk2021-11-05 16:33:27
Java
kokapuk, 2021-11-05 16:33:27

How can a string be formatted?

Hello, I recently encountered such a problem: I would like to format a string, as in C#.

int age = 63;
string a = $"you are {age} years old";

Is there a similar analog in java?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Roo, 2021-11-05
@kokapuk

String.format("you are %s years old" , age);

E
Egor P, 2021-11-05
@Egor4

int age = 63;
string a = "you are " +age+ "years old";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question