Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
We can use the string type to store text.
So far, we played around with Int variables also every time you update the passengers variable, the
ministry wanted you to print it, which we did, but our print statements were a bit boring in the sense
that it would be nice if each message came with some text.
For example, I'd rather print the number of passengers is nine, four or zero instead of just printing
plain old numbers.
So in this lesson, you're going to use the string type to store and update text.
String pretty much means text, so why is it called string?
That's a pretty rare name.
Well, think about a character is anything that you can type through your keyboard, like the letter
A, B or C, now the name string.
It makes sense if you think about text as something that strings together a bunch of characters.
OK, and there are three things we need to define a string variable, there is the string type such
that this variable named sentence can only store string value and the string value is just text wrap
and double quotes.
All right, inside the bus class, make a searing variable named sentence, string sentence is equal
to and in double quotes, will the right number of passengers put a colon with an empty space at the
end?
And print the value system, dart out.
Dot print, line sentence.
Compile the codes.
And run, runit.
And the sentence variable story is a tax value, which you printed using the print online function,
the easy stuff, but right now the sentence isn't finished in the sense that we need to connect the
passengers value at the end of the string after each update.
We want to achieve something like this.
So for now, remove the first print lights stem and it's pretty useless.
And we're going to come back to this class because right now we're going to make a separate class where
we learn how to join strength's.
So inside the section to project make a new file named Joining Strings Java and the Joining Strings
class must have the main method.
OK, you can join string values with the plus simple.
This involves text added to more text, and the result is a joint text.
It's pretty simple, really.
Joining strong values is common if you need to connect a placeholder, a small piece of text as part
of a longer sentence.
So inside the joining strings class, make a variable named sentence.
String sentence.
Is equal to in double quotes.
His name is.
With a colon and empty space at the end.
Never going to make another variable named Placeholder String.
Placeholder.
Is equal to in double quotes, Harry.
Now, using the plus sign, you can connect the two string values and print them system dot out.
Dot print line, we're going to connect the sentence value to our placeholder.
Compile the code.
And run, runit.
His name is Harry Nice.
So first off, the sentence variable store is a tax value.
The placeholder store is a tax value as well, and you were able to join both values and printed them.
You can also join a string value with an integer using the plus symbol and connecting a number to the
end of a string is very common.
This involves text the plus icon and a number and what happens is pretty cool, the number blends into
the strich.
So we're going to test this in Java.
Let's create two more variables and points is equal to 50.
String announcement is equal to and I'm going to start this thing off with empty space and then follow
it up with points for Gryffindor.
All right, now print those two variables is one system, dot out, dot print, nine points plus announcement.
Compile the code.
Well, that was a word glitch and run it and 50 points for Gryffindor, the result is a complete sentence.
The points variable stores a number, the announcements, variable stores text.
Then you added both variables.
And when you do that, the number blends into the string, and that is Java embeds the number inside
the string.
OK, back to the bus with this knowledge, I believe you can confidently wrap up the bus application
every time we update the number of passengers, we're going to print the new value as part of a longer
sentence.
So we'll say sentence.
Plus, passengers, and we're going to copy this two more times.
We're in a compile the codes.
And this looks pretty good after each update, you printed a string of that connect sentence to the
number of passengers and the ministry is more than happy with your work.
They're delighted.
All right, there's just one last thing I want to go over, just like we updated variables, you can
also update string variables.
So we'll say sentence is equal to in double quotes, end of shift.
Test them, dart out, dart print line sentence.
Rolnik and Palakkad.
All right, the central stores in your valley, which we printed at the end of the driver's shift,
although you know what, instead of updating the sun's variable, it's more concise than just print
and shift directly.
OK, I think our app is now complete.
There is one last note I want to leave you with when joining string values, don't forget Whitespace.
If you look at the code, notice that I leave whitespace in my strings.
If you don't leave whitespace, your sentences are going to look awkward.
Must try to remove the white space here.
Now, I'm going to rerun the code.
As you can see, this looks pretty bad and awkward, Java doesn't add white space for you.
You need to do it yourself either by connecting in white space between the two variables.
So we're going to compile the code and run that.
This works just fine besides white space in between the two strings and connect everything, but I prefer
my method where I just leave some white space inside the string value.
So now remove those.
And leave whitespace here in here.
And both methods are fine, but honestly preferred this one, I find it easier to just add whitespace
inside the string as opposed to adding an externally.
In this lesson, you learned about string variables, string variables allow you to store text and you
define two string variables is that each one stored a text value.
You learn to join both string values with the plus symbol, but sometimes you need to connect a string
with a number and the plus operator can be used to blend the number inside a string.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.