This community-built FAQ covers the “String Concatenation” exercise from the lesson “Learn Java: Manipulating Variables”.
Paths and Courses
This exercise can be found in the following Codecademy content:
Learn Java
FAQs on the exercise String Concatenation
There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
Need broader help or resources? Head here.
Looking for motivation to keep learning? Join our wider discussions.
Learn more about how to use this guide.
Found a bug? Report it!
Have a question about your account or billing? Reach out to our customer support team!
None of the above? Find out where to ask other questions here!
why is the string zooDescription written like this ?
public class Zoo {
public static void main(String args){
int animals = 12;
String species = “zebra”;
String zooDescription = "Our zoo has " + animals + " " + species + “s!”;
System.out.println(zooDescription);
}
}
1 Like
Hi. It took me a little bit to figure out why the solution was correct too.
The seemingly random double quotes between ‘+ animals’ and ‘+ species’ contain an invisible space which is needed to have a space between the number of animals and type of species. Without the double quotes around the space, the result would be “12zebras!” instead of the correct “12 zebras!”.
Hope that helps.
3 Likes
buenas tardes tengo una pregunta … estoy poniendo las comillas dobles , pero no me sale ninigun espacio entre el numero de animales y las cebras
Hi andrea,
can u tell me why this “s!”; has mentioned in String zooDescription
String zooDescription = "Our zoo has " + animals + " " + species + “s!”;
Hello, can anyone tell me where I am going wrong please? I have viewed the solution and I am having difficulty finding out why it won’t let me move on from this point. I appreciate your help, thank you!
Sincerely,
Mitch
1 Like
strings need to be an exact match, from what i see, the expected output should be zebras
, not zebra's
1 Like
Hello stetim94, thank you very much for your help and how quickly you responded. Haha, it’s funny how the little things like that can trip you up. I fixed it and moved on, thank you again.
1 Like
did you type it as “” (with no space between the quotation marks) or as " " (which has a space in between the quotation marks)?
Hi!
I don’t understand the use of “s!”. There is no description available about it. I wrote my solution as
String zooDescription = "Our zoo has " + animals + species;
Please someone explain “s!” to me.
This thing was not even used in the example
int balance = 10000;
String message = "Your balance is: " + balance;
System.out.println(message);
Thanks!
1 Like
its just a string? To make the animal name plural and let the sentence end with an exclamation mark.
string concatenation (using +
) allow us to insert variables inside a string
3 Likes
As far as I can tell I’ve typed it correctly but it wont let me move past, can anyone see what my error is?
EDIT: Of course right after I post this I see the missing + between animals and " "
Anyone know what’s wrong here? The system is not letting me pass.
I guess the system was designed to use if else statement to identify whether we have inputted the right code into it. the semicolon ; should be next to “s!” without any white space. Else the system will mark you as incorrect.
public class Zoo {
public static void main(String[] args){
int animals = 12;
String species = "zebra";
String zooDescription = "Our zoo has" + animals + " " + species + "s!";
System.out.println (zooDescription);
}
}
I need help the programm dont let pass me.
Help please Thanks
space between has
and <animals>
is missing → has12 vs has 12
Hello Stetim,
I need some help. I have the same question as Mr. Text over here, except I didn’t make any typos whatsoever. What should I do?
nevermind, i had an extra space LMAO