"Hello"
"Goodbye"
"G"
" "
""
Which of these five options are strings?
Everything is clear with the first two, these are exactly strings, we have already worked with similar constructions and said that strings are character sets.
Any single character in quotes is a string. The empty string " "
is also a string. That is, we consider everything to be inside the quotes, even if it is a space, one character or no characters at all.
Imagine that you want to print dragon's mother line. The apostrophe before the letter s is the same character as a single quote. Let's try:
This version of the program will work correctly:
System.out.println("Dragon's mother");
And what if we want to create such a string:
Dragon's mother said "No"
It contains both single and double quotes. How to be in this situation?
To do this, use the escape character: \
. If you put \
before the quotation mark (single or double), it will mean that the quotation mark should be viewed not as the beginning or end of the line, but as part of the line.
System.out.println("Dragon's mother said \"No\"");
Write a program that displays:
"Khal Drogo's favorite word is "athjahakar""
The program should display this phrase exactly. Note the quotes at the beginning and at the end of a phrase.
If you've reached a deadlock it's time to ask your question in the «Discussions». How ask a question correctly:
Tests are designed so that they test the solution in different ways and against different data. Often the solution works with one kind of input data but doesn't work with others. Check the «Tests» tab to figure this out, you can find hints at the error output.
It's fine. 🙆 One task in programming can be solved in many different ways. If your code passed all tests, it complies with the task conditions.
In some rare cases, the solution may be adjusted to the tests, but this can be seen immediately.
It's hard to make educational materials that will suit everyone. We do our best but there is always something to improve. If you see a material that is not clear to you, describe the problem in “Discussions”. It will be great if you'll write unclear points in the question form. Usually, we need a few days for corrections.
By the way, you can participate in courses improvement. There is a link below to the lessons course code which you can edit right in your browser.