1 / 17

Day 8 Integers , Remainders, and other Primitive Types

Day 8 Integers , Remainders, and other Primitive Types. Primitive Types & Details. Float: non-exponential numbers. End your number with f (i.e., 2.33f) Try working with it. Float: exponential numbers. i.e., 2.44E5f means 2.44 x 10^5 i.e., 2.44E-5f means 2.44 x 10 ^(-5)

renate
Download Presentation

Day 8 Integers , Remainders, and other Primitive Types

An Image/Link below is provided (as is) to download presentation 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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Day 8Integers, Remainders, and other Primitive Types

  2. Primitive Types & Details

  3. Float: non-exponential numbers • End your number with f (i.e., 2.33f) • Try working with it

  4. Float: exponential numbers • i.e., 2.44E5f means 2.44 x 10^5 • i.e., 2.44E-5f means 2.44 x 10^(-5) • Print these out

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

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

  7. 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 ?

  8. 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 ?

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

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

  11. 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

  12. 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;

  13. 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…

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

  15. 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;

  16. Graphics Supplement Handout on Applet

  17. Day 44.1 Class & Method Definitions

More Related