hello everyone alex here from
wornoffkeys.com and in this quick
video i'm going to show you how you can
use compound assignment operators
to add numbers to other numbers in an
easier way
so real quick before we start if you do
need help with anything
feel free to leave a comment down below
or better yet ask in the worn off keys
discord server and i'm sure someone will
be able to help you there
so with that said let's get started here
i'm going to demonstrate a previous
videos example
of creating a number so int number
equals 50
and then let's say we want to add 10 to
this number we can then say
number equals number plus 10.
at this point number would equal 60
because we are saying number equals the
result this expression
which is the current value of number
plus 10.
there's actually an easier way to do
this we can say number
plus equal to 10 and this line right
here line 8
is the exact same thing as line 7. to
demonstrate this i can delete this line
and then i can print this out so sout
and i can press enter to generate this
statement within intellij
and then i can print out number i can
then run our program with the green
arrow up here
and we now see 60. now of course you can
use subtraction with this as well
so if i run this we should see 40 and
you can use multiplication
and division so this is a quicker way
to add subtract multiply and divide with
your numbers and there's also another
thing i want to show you within this
video
that is how to add two variables
together it's actually the same exact
concept
so let's say int number two these aren't
very meaningful names but they work for
examples
we'll say 10 we can say number is plus
equal to
number two now if i run this what do you
think the output is going to be
let's go ahead and click on this and we
see 60 right here
so number one is defined and 50 is set
inside of there
and then number two is defined and 10 is
set inside of there
we are then saying number plus equal
number two
which is the exact same thing as number
equals number
plus number two so number two equals 10
and number equals 50 and so the sum here
is going to be 60 which is then assigned
to
this variable named number and so this
is how you're going to use compound
assignment operators in order to quickly
add numbers together
in the next video i'm going to show you
how you can use if statements which is
one of the conditional statements we can
use
in order to have certain code run
whenever a certain condition is met
they are very powerful and one of the
more common features used within java
programs
so we'll be covering that in the next
video thanks for watching this java
tutorial
if you need help leave a comment down
below or ask in the worn off keys
discord which will be linked in the
video description
if you want access to the source code
for this video a link to the github
repository can found
in the video description as well if you
found this video helpful
please consider liking and subscribing
with the notifications on so you get
notified whenever i release a future
java tutorials
