Qtr No. 213, New Town Yehlanka Indore 454775
You have a StringTemplate with the following definition:
"Hello, $name! Your favorite color is $color and you are $age years old."
Which of the following code snippets will correctly format the template with the provided data?
StringTemplate st = new StringTemplate("Hello, $name! Your favorite color is $color and you are $age years old.");
String name = "Alice";
String color = "Blue";
int age = 30;
st.name = name;
st.color = color;
st.age = age;
String output = st.toString();
System.out.println(output);
StringTemplate st = new StringTemplate("Hello, $name! Your favorite color is $color and you are $age years old.");
String name = "Alice";
String color = "Blue";
int age = 30;
st.setAttribute("name", name);
st.setAttribute("color", color);
st.setAttribute("age", age);
String output = st.toString();
System.out.println(output);
StringTemplate st = new StringTemplate("Hello, #name! Your favorite color is #color and you are #age years old.");
String name = "Alice";
String color = "Blue";
int age = 30;
String output = st.toString();
System.out.println(output);
StringTemplate st = new StringTemplate("Hello, $name! Your favorite color is $color and you are $age years old.");
String output = st.toString();
System.out.println(output);
To get all Infosys Certified Java SE 21 Developer Exam questions Join Group https://bit.ly/infy_premium_group
We're passionate about offering best placement materials and courses!! A one stop place for Placement Materials. We daily post Offcampus updates and Placement Materials.
Qtr No. 213, New Town Yehlanka Indore 454775
admin@prepflix.in