170 likes | 323 Views
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)
E N D
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) • Print these out
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 % • For example, in Java, 55/25 is ?
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 ?
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 ?
Sample Problem #1 • You have 18 cents. How many nickels and pennies can that amount be broken into using Java’s / and % operators?
Sample Problem #2 • You have 37 cents. How many quarters, dimes and pennies can that amount be broken into using Java’s / and % operators?
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
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;
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…
Documentation & Style Comments can simply be inserted to describe your code or your variables by using two forward slashes //
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;
Graphics Supplement Handout on Applet