Week 5, Notes 2

See ../demos/W05N02.java

Math class methods – con’t

Look in the API to find definitions for these methods.

 

round()

random()  //  returns a double  0.0 <= returnValue < 1.0

‘Random’ numbers

Actually a sequence of values starting from a predetermined ‘seed’

Everytime you call random(), you get a new number based on the last ‘random’ number you generated.

Integer division

Review of Week02_Notes02:

int a = 7;

int b = 5;

 

a / b == 1

 

/ => 4th grade division – the answer is the quotient

% => 4th grade division – the answer is the remainder

Integer promotion

declaring a double variable and assigning an integer to it, promotes the integer to a double.

 

Doing an operation on an integer and a double promotes the integer to a double.

Floating point equality

 

2.0 / 3 != .666667

 

Use a tolerance value, e.g., .0001 to determine whether two double quantities are ‘equal’

 

if (Math.abs(d1 - d2) < tolerance)

     // d1 and d2 are ‘equal’