Java Double.compareTo() Method

The compareTo() method of Double class compares two double values numerically.

Syntax

Parameters

anotherDouble - the Double value to be compared

Return value

This method returns the value-

  • Zero, if anotherDouble has same value as this Double.
  • Positive value, if anotherDouble has a greater value than that of this Double.
  • Negative value, if anotherDouble has less value than that of this Double.

Example 1

Output:

10.44 is greater.
Answer after subtraction is= 0.4399999999999995

Example 2

Output:

Enter your percentage
48
Congrats you are eligible for the Exam.