Java Float compare

Description

Java Float compare


public class Main {
    //  www .j av a 2  s .c o  m
    public static void main(String[] args){

        Float float1 = new Float("19.675");
        Float float2 = new Float("71.3826");
        Float float3 = new Float("23.373");
        int myInt = new Integer(5);
        
        System.out.println("-- Using compareTo --");
        System.out.println(float1.compareTo(float3));
        System.out.println(float2.compareTo(float3));
        System.out.println(float1.compareTo(float1));
        System.out.println(float3.compareTo(float2));
       
        
        System.out.println("-- Using compare --");
        System.out.println(Float.compare(float1, float3));
        System.out.println(Float.compare(float2, float3));
        System.out.println(Float.compare(float1, float1));
        System.out.println(Float.compare(float3, float2));
        

    }
    
}



PreviousNext

Related