Javatpoint Logo
Javatpoint Logo

Java Float compare() method

The compare() method of Java Float class compares the two specified float values i.e. f1 and f2.

Syntax:

Parameters:

The parameters passed are f1(the first float value) and f2(the second float value).

Return Value:

This method returns the integer value of the argument.

  • Returns a zero if value of f1 is same as value of f2(f1 = f2).
  • Return a positive value if f1 is greater than f2(f1 > f2).
  • Return a negative value if f1 is less than f2(f1

Example 1

Test it Now

Output:

10.0 is smaller 50.44 is greater.

Example 2

Test it Now

Output:

Error:(13, 26) java: method compare in class java.lang.Float cannot be applied to given types;
  required: float,float
  found: java.lang.Float
  reason: actual and formal argument lists differ in length

It is compulsory to pass two arguments in Float class compare() method otherwise, it will give you an error.


Next TopicJava Float





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA