• Managing your videos in Amara teams just got easier! Read about it in our latest blog post. Hide

← Integer Arithmetic - Intro to Java Programming

• 2 Followers
• 18 Lines

Get Embed Code x Embed video Use the following code to embed this video. See our usage guide for more details on embedding. Paste this in your document somewhere (closest to the closing body tag is preferable): ```<script type="text/javascript" src='https://amara.org/embedder-iframe'></script> ``` Paste this inside your HTML body, where you want to include the widget: ```<div class="amara-embed" data-url="http://www.youtube.com/watch?v=hfMBIuYhhH8" data-team="udacity"></div> ``` 6 Languages

Showing Revision 5 created 05/25/2016 by Udacity Robot.

1. You just worked with Sarah on a few questions on arithmetic operations. But I
2. want to talk about the somewhat trickier aspect on how to do division with
3. integers. Let's say I have a piggy bank full of pennies, and then I want to
4. know how many dollars do I have. In Java, I can computer that with a division
5. operation, and there's a bit of a catch. When both operands on the left and on
6. the right hand side of the division slash our integers, then the quotient is
7. formed, and the remainder is discarded. Mathematically, 435 divided by 100 is
8. of course 4.35. And then, the 0.35 is gone. The leftover is 4 as an integer.
9. And that number here is now saved as the dollars. That's just what we want,
10. right? 435 pennies is \$4. What if we also want the pennies, for that we have a
11. different operator called the modulus operator, and we often just pronounce it
12. as mod. By the operand on the right, let's try that out with 435. 435 divided
13. by 100 is 4. So, there's 4 times 100 going in here. When we take those off,
14. we're left with a remainder of 35. That was no longer divisble by 100. That's
15. what the remainder operator yields. You can see that by making an integer
16. division by 100, and then also a reminder operation with 100 then we get the
17. dollars and the cents value. Now, it's time for you try this tell me what is.
18. Pennies integer divided by ten and pennies mod 10.