66
Java Double compare() Method
The compare() method of Java Double class compares two specified double values.
Syntax
Parameters
Two parameters-
d1- The first double to be compared.
d2- The second double to be compared.
Return value
This method will return value –
- zero, if d1 is numerically equal to d2.
- less than zero, if d1 is numerically less than d2.
- greater than zero, if d1 is numerically greater than
- d2.
Example 1
Output:
10.56 is greater. Difference is= 0.5600000000000005.
Example 2
Output:
Error:(13, 26) java: method compare in class java.lang.Double cannot be applied to given types; required: double,double found: java.lang.Double reason: actual and formal argument lists differ in length
Example 3
Output:
Enter your Family income 45000 Sorry, You are not eligible for the subsidy
Next TopicJava Double