Double.compare(): This method is available in java.lang.Double class of Java.
Syntax:
int java.lang.Double.compare(double d1, double d2)
This method takes two arguments of type double as its parameters. This method compares the two specified double values.
Parameters: Two parameters are required for this method.
d1: the first double to compare.
d2: the second double to compare.
Returns:
1. The value 0 if d1 is numerically equal to d2.
2. A value less than 0 if d1 is numerically less than d2.
3. A value greater than 0if d1 is numerically greater than d2.
For Example:
double d1 = 10.8, d2 = 17.9
Double.compare(d1,d2) = > It returns -1.
Approach
Java
public class DoubleCompare {public static void main(String[] args) {double d1 = 10.8, d2 = 17.9;System.out.println(Double.compare(d1, d2));}}
Output:
-1
No comments:
Post a Comment