1 00:00:00,480 --> 00:00:06,060 Onwards, the part two in the first video we went through, the first four operators and we saw a very 2 00:00:06,060 --> 00:00:12,000 cool pattern in operation between whole numbers will return a whole number and an operation between 3 00:00:12,000 --> 00:00:14,170 decimals always returns a decimal. 4 00:00:15,150 --> 00:00:19,110 Now you're going to see the very same pattern as we go through the remaining five operators. 5 00:00:23,840 --> 00:00:30,080 And the first one is the modulus operator, which is expressed by the percent sign and what the modulus 6 00:00:30,080 --> 00:00:32,330 does is it returns the remainder of a division. 7 00:00:33,080 --> 00:00:40,070 When you divide two numbers like ten divided by two, what remains is the modulus, in this case, the 8 00:00:40,070 --> 00:00:42,260 modulus from dividing ten by two is zero. 9 00:00:44,720 --> 00:00:52,760 And in Java, the modulus operation involves the dividend and the deviser, this operation will divide 10 00:00:52,760 --> 00:00:57,740 ten by two, but it won't return the result of the division, it returns the remainder. 11 00:00:58,730 --> 00:01:00,620 But why do we care about the remainder? 12 00:01:01,430 --> 00:01:08,090 It's very useful if you want to identify odd or even numbers when you divide an even number by two like 13 00:01:08,090 --> 00:01:08,610 10. 14 00:01:08,660 --> 00:01:09,980 The remainder is zero. 15 00:01:17,220 --> 00:01:22,950 When you divide an odd number by two, the remainder is not zero, which makes five an odd number. 16 00:01:30,330 --> 00:01:31,740 So we can prove this in our code. 17 00:01:31,860 --> 00:01:34,140 We're going to grab the last two strings from the article. 18 00:01:42,190 --> 00:01:45,730 Comment them out and we're going to put them in print statements. 19 00:01:47,290 --> 00:01:49,990 System, dot, dot, dot, print line. 20 00:01:52,520 --> 00:01:55,010 System out print line. 21 00:01:58,440 --> 00:02:00,510 And we'll just put in both string's. 22 00:02:15,350 --> 00:02:20,510 OK, so at the end of the first string, we're going to connect the modulus from dividing 10 by two. 23 00:02:30,460 --> 00:02:34,300 And in the second string will connect the modulus from dividing five by two. 24 00:02:40,280 --> 00:02:47,630 OK, compile the code and run it, and indeed the modulus from the Vining, ten by two is zero, which 25 00:02:47,630 --> 00:02:53,690 makes ten even and the modulus from dividing five by one is not zero, which makes five an odd number. 26 00:02:57,370 --> 00:03:03,250 All right, let's talk about the ad one operator whose symbol is represented by two plus signs and what 27 00:03:03,250 --> 00:03:06,370 this operator does is it increases the value by one. 28 00:03:07,150 --> 00:03:13,000 And this operation is very common for integer variables because suppose you had a counter variable of 29 00:03:13,000 --> 00:03:14,680 type event which starts at zero. 30 00:03:15,370 --> 00:03:22,180 And when you place plus plus next to the variable, it increases the counter value by one doing so three 31 00:03:22,180 --> 00:03:22,630 times. 32 00:03:22,660 --> 00:03:24,340 The counter value ends up being three. 33 00:03:24,940 --> 00:03:28,740 This is pretty straightforward and let's make it official by doing it in code. 34 00:03:29,680 --> 00:03:32,620 So I'll right int counter. 35 00:03:34,770 --> 00:03:41,700 Is equal to zero and will increase the value by one three times countered plus plus. 36 00:03:42,850 --> 00:03:44,560 Counter plus plus. 37 00:03:47,520 --> 00:03:49,260 Encounter plus plus. 38 00:03:52,040 --> 00:03:53,780 Then I'm going to print system. 39 00:03:56,790 --> 00:03:59,090 Dart out front line. 40 00:04:06,820 --> 00:04:08,710 And we'll connect the counter value. 41 00:04:15,130 --> 00:04:16,269 Compile your code. 42 00:04:22,380 --> 00:04:24,600 And sure enough, the counter equals three. 43 00:04:28,920 --> 00:04:34,350 Conversely, the subtract one operator is represented by two minus signs, and it's a role that's a 44 00:04:34,350 --> 00:04:35,760 decrease value by one. 45 00:04:36,600 --> 00:04:41,820 This operation is also common for integer variables because suppose you had a counter variable that 46 00:04:41,820 --> 00:04:47,790 starts at three and when you place minus minus next to the variable, it decreases the value by one. 47 00:04:49,050 --> 00:04:51,450 Do this three times in the counter ends up being zero. 48 00:04:52,500 --> 00:04:54,010 OK, we can try this in Java. 49 00:04:54,960 --> 00:04:57,630 We're going to write counter minus minus. 50 00:04:59,980 --> 00:05:04,570 Counter minus, minus and one more time, counter minus, minus. 51 00:05:05,500 --> 00:05:08,050 We're going to copy and paste the first print statements. 52 00:05:11,780 --> 00:05:13,040 Recompile the code. 53 00:05:21,270 --> 00:05:27,240 Subtracting one three times, as expected, return zero, because the counter starts at three in each 54 00:05:27,240 --> 00:05:29,520 decrement, removes one from the counter value. 55 00:05:30,640 --> 00:05:37,120 All right, let's talk about the ad buy operator, whose symbol is Express's plus equals the ad buy 56 00:05:37,120 --> 00:05:37,500 operator. 57 00:05:37,510 --> 00:05:42,550 What it does is it adds the value on the right and we already use it in the updating variables video. 58 00:05:42,970 --> 00:05:45,970 You saw an example where a bus started with zero passengers. 59 00:05:46,510 --> 00:05:51,250 The plus equals operator was used to update the value by adding nine the value on the right. 60 00:05:52,640 --> 00:05:58,460 And conversely, we also have a tracked by operator, which you've already seen as well, and this one 61 00:05:58,460 --> 00:06:00,170 subtracts the value on the rights. 62 00:06:00,770 --> 00:06:03,020 We also use this in the updating variables video. 63 00:06:03,020 --> 00:06:07,310 So from the same example, the bus dropped off five passengers, then four. 64 00:06:07,790 --> 00:06:11,680 And in both cases, the minus equals operator subtracts the value on the right. 65 00:06:14,300 --> 00:06:20,210 All right, let's recap, we just used every math operator in Java in every math operation follows a 66 00:06:20,210 --> 00:06:22,400 very nice pattern to study. 67 00:06:22,400 --> 00:06:28,010 Math operation between two whole numbers will always return a whole number and then operation between 68 00:06:28,010 --> 00:06:30,350 decimals will always preserve the decimal. 69 00:06:31,890 --> 00:06:37,200 And now I'm going to recap all the operations we looked at so far, and they are the plus operator to 70 00:06:37,200 --> 00:06:43,920 add values, subtraction, to subtract values, multiplication and division, to multiply and divide 71 00:06:43,920 --> 00:06:44,520 values. 72 00:06:45,300 --> 00:06:48,480 The modulus operator returns the remainder of a division. 73 00:06:49,110 --> 00:06:56,790 The add one operator increases the value by one e subtract one operator decreases a value by one, add 74 00:06:56,790 --> 00:07:03,600 by increases in value by adding the number on the right and subtract by decreases a value by subtracting 75 00:07:03,600 --> 00:07:04,970 the number on the rights. 76 00:07:05,610 --> 00:07:06,270 That is all.