Day 4 Integers, Remainders, and other Primitive Types

1 / 15

# Day 4 Integers, Remainders, and other Primitive Types - PowerPoint PPT Presentation

Day 4 Integers, Remainders, and other Primitive Types. Primitive Types & Details. Integers and Remainders. To divide two numbers, use / To get the remainder of two numbers, use %. Integers and Remainders. To divide two numbers, use / To get the remainder of two numbers, use %

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## Day 4 Integers, Remainders, and other Primitive Types

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
1. Day 4Integers, Remainders, and other Primitive Types

2. Primitive Types & Details

3. Integers and Remainders • To divide two numbers, use / • To get the remainder of two numbers, use %

4. Integers and Remainders • To divide two numbers, use / • To get the remainder of two numbers, use % • For example, in Java, 55/25 is ?

5. Integers and Remainders • To divide two numbers, use / • To get the remainder of two numbers, use % • For example, in Java, 55/25 is ? • And 55%25 is ?

6. Integers and Remainders • To divide two numbers, use / • To get the remainder of two numbers, use % • For example, in Java, 55/25 is ? • And 55%25 is ?

7. Sample Problem #1 • You have 18 cents. How many nickels and pennies can that amount be broken into using Java’s / and % operators?

8. Sample Problem #2 • You have 37 cents. How many quarters, dimes and pennies can that amount be broken into using Java’s / and % operators?

9. Sample Problem #3 • Vending Machine Change Calculator: Write a code that produces the following output:87 cents in coins will be: 3 quarters1 dime0 nickels2 pennies

10. Solution to Problem #3 Body: quarters = amount/25;amount = amount%25; dimes = amount/10;amount = amount%10;nickels = amount/5;amount = amount%5; pennies = amount;

11. Documentation & Style All java programs from hereon must use comments and descriptions in the code: import java.util.*;/**Author: Sam RudnerDate: 09/14/2014*/ public class AutoMobile…

12. Documentation & Style Comments can simply be inserted to describe your code or your variables by using two forward slashes //

13. Naming Constants • For something like PI = 3.14159 …. It can’t be a variable. It’s a constant that can’t be changed. To define a constant, write: public static final variable type = constant;for example:public static final double MortgageRate = 5.78;

14. Graphics Supplement Handout on Applet

15. Day 44.1 Class & Method Definitions