Java Float int compareTo() MethodThe compareTo() method of Java Float class compares two Float objects numerically. The sign of the integer value returned is same as that would be returned by the compare(float f1, float f2) method. Syntax:Parameters:anotherFloat is the float parameter passed, which is to be compared. Return Value:This method returns the integer value of the argument.
Example 1Test it NowOutput: 50.44 is greater. Answer after subtraction is 40.44. Example 2Test it NowOutput: Enter your age 18 Congrats you are an adult now.From now you can vote. Example 3Test it NowOutput: Error:(17, 23) java: method compareTo in class java.lang.Float cannot be applied to given types; required: java.lang.Float found: no arguments reason: actual and formal argument lists differ in length It is compulsory to pass an arguments in Float class compareTo() method, otherwise it will give you an error.
Next TopicJava Float
|