Home » Java Double compare() Method with Examples

Java Double compare() Method with Examples

by Online Tutorials Library

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

Test it Now

Output:

10.56 is greater.  Difference is= 0.5600000000000005.  

Example 2

Test it Now

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

Test it Now

Output:

Enter your Family income  45000  Sorry, You are not eligible for the subsidy  

Next TopicJava Double

You may also like