All language subtitles for 003 Updating Variables_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian Download
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

You can update the value inside a variable.

You saw that defining a variable and storing a value is pretty simple.

You need to write the type of value we can store, this variable in particular can only store integer

values.

You also need to write the variable name and the value that you want to store.

So available stores information about your app, but as time passes, things change and you need to

update that information.

That's why in this video, you're going to learn to update the value inside a variable.

First thing I need you to do is create a new class by yourself inside the section to project make a

new file named Buster Java and then make sure the bus class has the main method.

Take a couple of seconds to do that.

All right, how do you update variables if you want to update a variable, it's fairly simple.

Each have to set it equal to a new value and the value inside changes every time you update it.

I prepared a fun example so that we can learn more about this, you, the Java prodigy, you found a

job at the Ministry of Transportation in the ministry wants you to build a Java program, the programming

you to print, how many passengers are inside a bus, and then you need to print the number of passengers

at every stop.

So I'm going to assume you ready set the class up and before we start our code, you'll notice that

the terminal output is pretty cluttered.

You could just close the terminal, open a new terminal, but that's pretty lame if you ask me.

We can instead clear the terminal output by writing.

Clear.

Nice, this command is very useful, and I'm going to add it to your cheat sheet.

OK, so the bus driver is starting his shift.

He boarded the bus and naturally the bus is empty and he starts with zero passengers and passengers

is equal to zero.

Don't forget your semicolon.

All right, his first stop is the river station, let's say there he picks up nine passengers.

So we need to update the number of passengers by nine passengers.

Is equal to passengers.

Plus nine.

Then after you update the number of passengers, you can print the new value system, dot out dot print

line passengers.

All right, compiling the code, Java Sea Bass Java and running it.

Clearly now there are nine passengers in the second line, you said passengers equal to itself, zero

plus nine, and now it stores a value of nine.

Now the bus driver is approaching the Sugar Mountain sweetshop in, your passengers go crazy for sweets.

So there he drops off five passengers.

Once again, you need to update the number of passengers that is passengers is equal to passengers minus

five.

And after you update the value print system, dot, dot, dot, print line passengers.

And using the up key, go ahead and compile the code.

All right, we started with zero passengers.

The bus driver picked up nine and dropped off five.

So the pattern follows four subtraction, the computer sets the value of passengers equal to itself,

nine minus five.

Now, there are four passengers in the bus and let's say the last stop is the post office and they're

the bus driver drops off the remaining passengers.

So passengers equal to passengers minus four.

And we're going to print the value system, dot, dot, dot, print line passengers.

Recompile your code and run it.

And everything works out as expected.

Your application updates information at every stop.

The bus starts with zero passengers, picks up nine.

Drops out five.

And drops the rest.

This is a pretty common way of updating integer variables, but there is an easier way.

And it's known as the plus equals operator, the plus equals operator updates a variable by adding the

value on the right.

So you can replace the first update with the plus equals operator passengers plus equals nine.

And if you ask me, this looks a lot better.

Let's see if it works.

And indeed, it does.

Passenger starts at zero and the plus equals operator updates the variable by adding nine fairly intuitive.

Now, what about these updates?

Well, there's also the minus equals operator.

This one, as you'll probably guess, it's tracks the value on the rights.

So you can replace the remaining updates with the minus equals operator.

Recompile the code.

And everything works as expected.

In both cases, it appears the variable by subtracting the value on the right.

And in this lesson, you learn to update the value inside a variable, you built a Java program that

updates the number of passengers when the bus picks up or drops passengers off plus equals and minus

equal to update the variable using the value on the right.

And that is all.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.