Hi everyone in this story.
I'm going to go ahead and touch about incrementing and decrementing in Java.
OK.
So first we need a Java project.
So just click on this fine Neo and then click on Java project.
OK so far the project name just taken here increment and decrement J.
And click on finish.
So as you can see here our project is now created.
So we need a class for our project.
So just click on this as RC for folder and then click on File new and click on class.
OK.
So for the class name just type in here increment
OK for the package name.
We need to reverse domain.
So just type in here com that's your name.
OK.
That's your project name.
OK.
Increment and decrements OK and for the modifiers to publish and make sure that you take this checkbox
he had public that it would mean method.
This is going to be the starting point for running our Java code.
OK.
And then click on finish.
So as you can see our class is now created.
So just delete this comment here.
And in order to make this edits have Area Vider just double click on the tap here increment decrement
that go with.
OK.
So as you can see here our editor area is now wider.
So now we can write our code.
OK.
So as you know I'm going to talk about incrementing
and decrementing in Java
so another common task required in programming is to add or subtract one value from an integer value.
OK those expressions have special operators which are called increment and decrement operators.
OK incrementing a valuable means adding one value to its value.
OK.
And decrement in a variable means subtracting one value from its value.
OK the increment operator is this operator here and
and the decrement operator is this operator here.
OK these operators are placed immediately after or before a variable name.
So let me actually show you some real examples in order to make this concept more clear for you.
OK.
So for example I want to create a variable the data type of my variable is int and the name of my variable
is.
For example my value OK.
And then I assign a value to my value.
But for example number seven.
And then at the end of my statement I need to put in a semi-colon.
So now I want to use these operators here.
OK so for example I want to add one value to the value of this variable here.
So as you know these operators are placed immediately after or before the variable name.
OK so I just need to refer to the name of my variable.
OK.
Now I want to put this operator here.
OK.
Increment operator.
So as you can see here.
So now if I want to output the value of this variable to the console I just need to type in here system
data out that print line and then inside Apprentice's I just need to refer to the name of my variable.
And then at the end of my statement I need to put in a semicolon.
OK.
So now if I run my project let's see what happens.
So as you can see this value is outputted to the console.
OK.
So this is the value of this variable here.
OK.
So now I want to use the increment operator here.
OK.
As you know these operators are placed immediately after or before the variable name.
OK.
So I just need to the first with the name of my variable my value.
OK.
And then I need to put in the increment operator here.
OK.
Plus plus.
And then I need to put the semi-colon at the end of my statement.
So now if I want to actually output the value of this variable to the console Let's see what happens.
System that out that princeling and an insight Apprentice's I need to refer to the name of my valuable
my value.
I need to put in a semi-colon.
So now if I run my project let's see what happens.
As you can see the first value is 7.
So this is the value of our value.
And we decided to output this value to the concert in line 14.
And as you can see this is the result of execution of this line of code here.
OK.
And in line 16 we decided to add one value to the value of our variable here.
OK.
And in line 17 we decided to output this value to the console.
So as you can see this is the value that is output to the console after the increment of this value.
OK.
So now let me try show you another example.
So now let me comment out this line of code here.
So for example again I want to actually subtract one value from this variable here.
OK.
I want to subtract one value from the value of this variable here.
OK.
So again I just need to refer to the name of my variable and then I need to put the increment operator
here minus minus and then at the end of my statement I need to put in a semi-colon.
So now if I want to output the value of this value over to the console system that out that print learn
and then inside the practices I just need to refer to the name of my valuable at the end of my statement.
I need to put in a semi-colon.
So now if I run my project as you can see the first value is 7 because this is the value that we assign
to our variable when we created this variable and in line 14 we decided to output this value to the
console.
So this is the value of a variable and in line 19 we decided to actually subtract one value from the
value of this variable here.
Okay.
And in line 29 we decided to output this value to the console.
So this is the value of our value bet after the subtraction.
OK.
So let me actually show you another example.
So let me ask you to comment out these lines of code here.
OK.
I want to declare another variable here is another value.
And then I can assign a value to my value but for example number 20.
Okay.
And I want to output the value of this variable to the console system that out that princeling.
And then inside Apprentice's I naturally first with the name of my valuable and other value.
And then at the end of my statement I need to put in a semicolon.
OK so now I want to actually run my project as you can see this value is out to the concert.
OK.
So for example I want to increment this value by 1.
OK.
So I just need to refer to the name of my body but in order to read it's value.
OK.
And now I want to increment the value of this variable by 1.
OK.
So I just need to put in here the increment operator plus plus.
And then I need to put in a semi-colon at the end of my statement.
So now if you run my project as you can see all I did I forgot to actually output the value of this
variable to the concert.
So system that out that creates land and then inside the.
I just need to refer to the name of my variable and at the end of my statement I need to put in a semicolon.
OK.
So now if I run my project as you can see this is the value that is output to the console.
And this is the value that we assigned to our variable when we actually created our variable.
Ok as you can see and in line 23 of we decided to output this value to the consumer.
So this is our value and in line 25 I decided to increment this value by 1.
Okay.
And in line 26 I decided to output this value to the console.
Okay.
Which is 21.
Okay.
So now that you actually comment out these lines of code here.
Okay.
And now I want to decrement the value of this variable by one.
Okay.
So again I need to refer to the name of my body.
And then I need to put in the decrement operator here.
Okay.
And then at the end of my statement I need to put in a semi-colon.
So now I want to output the value of this variable to the console.
So now let me actually run my project as you can see it's going to only output this value to the concert.
Okay.
And this value here is the result of execution of this line of code here.
Okay.
And as you know in line 28 I actually subtracted the value of this valuable one.
But as you can see it's not streaming the concert because I didn't write any code in order to output
the value of this variable after the discrimination.