Home / Programs / compare() Method in java Addition of Integer with Float
🚀 Programming Example

compare() Method in java Addition of Integer with Float

👁 1,016 Views
💻 Practical Program
📘 Step Learning

In this program you will learn about compare() Method in java Addition of Integer with Float.

💻 Program Code

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

        Integer intObj1 = new Integer (25);

        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));

        //Addition of Integer with Float
        Float f = intObj1.floatValue() + f1;
        System.out.println("Addition of intObj1 and f1: "+ intObj1 +"+" +f1+"=" +f );
    }

}

                        

🖥 Program Output

Comparing using compare f1 and f2: -1
Comparing using compare f1 and f3: 0
Addition of intObj1 and f1: 25+2.25=27.25
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.