division

6
Division CST200 Week 1 Instructor: Andreea Molnar

Upload: andreeamolnar

Post on 21-Jul-2015

2.416 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Division

Division

CST200 – Week 1

Instructor: Andreea Molnar

Page 2: Division

Division

% (remainder operator, modulus operator)

- returns the remainder after dividing the

second operand to the first

19 % 4 = 3

4 % 9 = 4

Page 3: Division

Division

% - the sign of the result is the sign of the

numerator (first operand)

-10 % 3 = -1

10 % -3 = 1

Page 4: Division

Division

/ - results depend on the type of the

operand

• if both operands are integers (byte, short,

int, long) the result is integer, any fractional

part of the result is discarded

• if either or both operands are floating point

(float, double) the result is floating point

Page 5: Division

Division14 / 5 = 2

14.0 / 5 = 2.8

14 / 5.0 = 2.8

14.0 / 5.0 = 2.8

(double) 14 / 5 = 2.8

(double) (14 / 5) = 2.0 // in this case the integer division

is performed first and afterwards the type casting

Page 6: Division

Summary

% (remainder operator, modulus operator)

- returns the remainder after dividing the

second operand to the first

/ - returns the results of division; result

depends on the type of the operand