How to compare a Float object with other Float object in Java

2 Answers

0 votes
package javaapplication1;
 
public class JavaApplication1 {
  
    public static void main(String[] args) {
   
        Float f1 = new Float(3.141592);
        Float f2 = new Float(3.141591);
        int n = f1.compareTo(f2);
 
        if (n > 0) {
            System.out.println("f1 > f2");
        } else if (n < 0) {
            System.out.println("f2 > f1");
        } else {
            System.out.println("f1 = f2");
        }
    }
}
  
/*
     
run:
     
f1 > f2
 
*/

 



answered Nov 4, 2016 by avibootz
0 votes
package javaapplication1;
 
public class JavaApplication1 {
  
    public static void main(String[] args) {
   
        Float f1 = new Float(3.141592);
        Float f2 = new Float(3.141591);
 
        if (f1 > f2) {
            System.out.println("f1 > f2");
        } else if (f2 > f1) {
            System.out.println("f2 > f1");
        } else {
            System.out.println("f1 = f2");
        }
    }
}
  
/*
     
run:
     
f1 > f2
 
*/

 



answered Nov 4, 2016 by avibootz

Related questions

2 answers 183 views
2 answers 213 views
1 answer 194 views
194 views asked Sep 23, 2016 by avibootz
1 answer 202 views
1 answer 167 views
4 answers 331 views
331 views asked Nov 8, 2016 by avibootz
...