1
Comparing Variable
•
Comparing floating point values for equality
•
Comparing characters
•
Comparing strings
•
Comparing objects
Comparing Float Values
Two floating point values are equal only if the match exactly
• Computations often result in slight differences that may be irrelevant
• To determine the equality of two floats, you may want to use the following technique:
if (Math.abs(f1 - f2) < TOLERANCE)
System.out.println ("Essentially equal");
The tolerance could be set to any appropriate level, such as 0.000001

This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*