Hello there, and welcome back to the Java development course. So, last time we went over logical operators, you had some homework to do your job was to create extend the application that we wrote previously to add support for or and inverted statements as well. So here essentially we should have done, okay, so here I just have an order Boolean, which is first or second, and then an inverted a Boolean, which is first and, and second. And that's inverted. So pretty simple, you know, nothing too complex. We already went over all of this in the last lesson.
So let's go and run it. Test it out. The real so true. False, there we go for true and and false is false. True or false is true. True and and false inverted is true.
So pretty simple. Let's go and actually test it out one last time, just true and true. And there we go. So true, and then true, is true, true. True or true is true, true and true inverted is false. So there we go.
So that essentially how we work with logical operators. So if you've got that very good, if not, again, try to understand it, and you're good to go for the rest of the course. So other than that, then let's get into the lesson. Alright, so today we're going to be going over assignment operators. And I promise this is the last lesson with operators. They can get quite boring.
I know and I'm sure at this point, you're like, what is the point of this is so boring, there's nothing to do? Don't worry. This is the last lesson after that we're done with operators, we can move on to more interesting things. Luckily, so let's go in and create a new class. assignment operator assignment operators, sign sign meant operators. There we go.
Seven operators actually very useful. And we've already used them quite a bit before. And there's a lot of things you can do with that assignment operator. So here they are. So let me go What actually do them? Write them out?
Equals plus equals minus equals times equals divided by equals. Let me see. So I think there's also a modulus equals or is they're not let me go check specifically. Okay, I checked specifically and there was one. Okay, so there we go. So these are the assignment operators.
So what do the assignment operators do? Well, first of all, let's go over the very simplest one, this equals operator. So let's say that we have an integer a, right, we now need to assign the value some value to a, so some number, we do that using the first operator A equals nine. There we go. All right, so very simple operator, just a equals nine. So now a is going to be equal to nine.
So nine is going to a, his value is going to be nine, and so on and so on. Now, what if we want to add one to a well, we would have to do a equals eight. plus one, right? That's gonna be 10. But we use a lot of code. What if we want to add 10 just just just for, for reference, we will have to do that.
But again, that's a lot of code, we can just do plus equals, there we go. So a plus equals 10 will add 10 to a, so 10 to nice, that's 19 and then put the value into a, so it will now be equal to 19. A is 19. There we go. Let's print it. System dot out dot print ln A.
There we go, and 19 as predicted. Okay, so other operators, we have the minus operator. So minus equals, this is all pretty self explanatory. Actually, no, I got rid of the Sit down. There we go. So a minus equals 10.
We'll subtract 10 from a and then put the result back into a let's run this negative one. As expected, we also have times equal 10, which is going to multiply a by 10, and then put the result back into a. There we go 90 again, as expected. And we could also do divided by let's make a 100 for this, just for kicks. And there we go. So 10 hundred divided by 10 is 10.
And then finally, we have the modulus operator as well. So we can go ahead and do modulus operator whoops, nope, minus operator. Let's make it 100 modulus 33. And this game is going to be one since 33 goes into 103 times with the remainder of ones that's 99. And there we go. So that is operators and that is how operators work.
Now, a couple things we need to clear up. So first of all, order of operations. I'm sure at this point, you're wondering about the order of operations. So let's say we have int a equals 12. And then int B equals a times 12 divided by three plus 14. I don't know maybe times five, right?
So order of operations do make a difference in this case. So if we go ahead and actually run this, we get actually no hi didn't print anything. system out print ln B, there we go. If we run this, we get 86. Right? But that's the thing.
There are order of operations here. So if And for that, we have parentheses. So we put parentheses here, and then I think, there to do it would be also here. That will change it. There we go. Yeah, as you can see, now it adds 12 to a, and then actually does the rest of the equation.
So order of operations are essentially in Java, just like in math. So first does multiplication and division, then addition and subtraction and so on. And so parentheses, we do have parentheses so we can put things into parentheses. And so then we, you know, can control the order of operations. If we don't close the parentheses we have they have to be closed. So if you don't close it, we get an error like this.
We can proceed actually, it will give us exception in thread main. So the problem is the, this thing here to answer that to complete it, and then that's, that will complete. Okay, so that is one of the things cleared up. Second of all, all of the operators that we went over that are for numbers, work with doubles and floats as well, so where they work with all numeric data types, so if we have a double b equals 3.4, we can now do System dot out dot print ln B times 45 divided by four for example, and we get 38 point 25. So just as an example, we can also do that as well. And so the same thing goes for float.
So if you have a float here, we can also do all mathematical operations on it. If we have a long here as well, we can do mathematical operations on long as well. There we go, and so on and so on. So with all data types, all numeric data types, we can perform operators on those data types. Okay, and so that is essentially how operators work in Java. All right, so, homework, this is going to be a little bit unusual homework.
Let me go and actually create the homework class really quickly. Create a homework class, the operators home, work, there we go. Okay, so for homework, what you're going to do is you're going to utilize the scanner class, as always, so scanner, S equals new scanner system.in. So you're going to utilize that scanner class. And what you're going to do is you're going to take in five doubles, you're going to take in five doubles. And then you're going to find the average of those doubles.
So I believe you've already done this. But now you're going to do it using the scanner classic involve two doubles. And third of all, you're going to do it with your new knowledge of operators. And it'll just make a little bit more sense. After you're after you average them. Go ahead and print.
The average of the doubles is and then you know, there was all you got, that will just look a little bit better. So yeah, so that essentially homework for this lesson, I wish you luck with it. It isn't all too difficult. We didn't actually ever go over how we can get doubles from a scanner. But it actually is the same thing is pretty much the same as getting an integer or a string or long or whatever we did. It's essentially the same exact thing for all of it.
So yeah, so I wish you luck. If you really get stuck going to look it up on Google, there are a ton of different resources that you can find for how you can get things From a scanner, engineer speaking, we're at a point now where there's just so much documentation on all of this and tutorials, that finding some problems on Stack Overflow or something isn't really too difficult. And actually, in the next lesson, we're actually going to take the lesson off from coding to research how we can actually find problems, solutions to problems using Stack Overflow and you know, Google in general. So yes, there's going to be next time. Anyway, for now, your homework is to get five doubles, then print the average say that the average of the doubles is and then the average that you got. So yeah, so I wish you luck with the homework and I'll see you next time.