Home / Programs / compare() Method in java
🚀 Programming Example

compare() Method in java

👁 1,135 Views
💻 Practical Program
📘 Step Learning
compare() Method in java

💻 Program Code

 public class WrappercompareMethod {
    public static void main (String args[]){

        Float f1 = new Float("2.25f");
        Float f2 = new Float("20.43f");
        Float f3 = new Float(2.25f);

        System.out.println("Comparing using compare f1 and f2: " +Float.compare(f1,f2));
        System.out.println("Comparing using compare f1 and f3: " +Float.compare(f1,f3));

    }

}

                        

🖥 Program Output

Comparing using compare f1 and f2: -1
Comparing using compare f1 and f3: 0
Press any key to continue . . .
                            
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.