{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture7 - PIC 20A Lecture 7 Comparing Values Boolean...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
PIC 20A Lecture 7: Comparing Values, Boolean Operators
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Comparing float and double values do not test for equality since round-off errors are common instead, test if two floating point numbers are “close enough” to each other you specify how close they need to be by defining a very small constant called EPSILON
Background image of page 2
An Example // say x and y are of type double // close here means they differ at most by .01 final double EPSILON = 1E-2; if (Math.abs(x-y) <= EPSILON) {System.out.println(x + “ close to ” + y);}
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Comparing Objects To see if two object references refer to the same object in memory, use == The operator == returns true if the two references store the same memory address and false otherwise Override the method boolean equals(Object o) to define what equality means for objects of your class
Background image of page 4