Java by API/java.lang/Float

Материал из Java эксперт
Перейти к: навигация, поиск

Float: byteValue()

  
    
    

public class Main {
  public static void main(String[] args) {
    Float fObj = new Float("10.50");
    byte b = fObj.byteValue();
    System.out.println(b);
    short s = fObj.shortValue();
    System.out.println(s);
    int i = fObj.intValue();
    System.out.println(i);
    float f = fObj.floatValue();
    System.out.println(f);
    double d = fObj.doubleValue();
    System.out.println(d);
  }
}





Float: compare(float f1, float f2)

  
public class Main {
  public static void main(String[] args) {
    float f1 = 5.5f;
    float f2 = 5.4f;
    int i1 = Float.rupare(f1, f2);
    if (i1 > 0) {
      System.out.println(">");
    } else if (i1 < 0) {
      System.out.println("<");
    } else {
      System.out.println("=");
    }
    Float fObj1 = new Float("5.5");
    Float fObj2 = new Float("5.4");
    int i2 = fObj1.rupareTo(fObj2);
    if (i2 > 0) {
      System.out.println(">");
    } else if (i2 < 0) {
      System.out.println("<");
    } else {
      System.out.println("=");
    }
  }
}





Float: compareTo(Float anotherFloat)

  
public class Main {
  public static void main(String[] args) {
    float f1 = 5.5f;
    float f2 = 5.4f;
    int i1 = Float.rupare(f1, f2);
    if (i1 > 0) {
      System.out.println(">");
    } else if (i1 < 0) {
      System.out.println("<");
    } else {
      System.out.println("=");
    }
    Float fObj1 = new Float("5.5");
    Float fObj2 = new Float("5.4");
    int i2 = fObj1.rupareTo(fObj2);
    if (i2 > 0) {
      System.out.println(">");
    } else if (i2 < 0) {
      System.out.println("<");
    } else {
      System.out.println("=");
    }
  }
}





Float: doubleValue()

  
    
    

public class Main {
  public static void main(String[] args) {
    Float fObj = new Float("10.50");
    byte b = fObj.byteValue();
    System.out.println(b);
    short s = fObj.shortValue();
    System.out.println(s);
    int i = fObj.intValue();
    System.out.println(i);
    float f = fObj.floatValue();
    System.out.println(f);
    double d = fObj.doubleValue();
    System.out.println(d);
  }
}





Float: floatValue()

  
public class Main {
  public static void main(String[] args) {
      float a = (Float.valueOf(args[0])).floatValue();
      float b = (Float.valueOf(args[1])).floatValue();
  }
}





Float: intValue()

  
    
    

public class Main {
  public static void main(String[] args) {
    Float fObj = new Float("10.50");
    byte b = fObj.byteValue();
    System.out.println(b);
    short s = fObj.shortValue();
    System.out.println(s);
    int i = fObj.intValue();
    System.out.println(i);
    float f = fObj.floatValue();
    System.out.println(f);
    double d = fObj.doubleValue();
    System.out.println(d);
  }
}





Float: isInfinite(float v)

  

public class Main {
  public static void main(String[] args) {
    float f = (float) 1 / 0;
    boolean b1 = Float.isInfinite(f);
    System.out.println(b1);
    Float fObj = new Float(f);
    boolean b2 = fObj.isInfinite();
    System.out.println(b2);
  }
}





Float.isNaN() Returns true if this Float value is a Not-a-Number (NaN),

  
    
    
public class Main {
  public static void main(String[] args) {
    float f = (float) Math.sqrt(-10);
    boolean b1 = Float.isNaN(f);
    System.out.println(b1);
    Float fObj = new Float(f);
    boolean b2 = fObj.isNaN();
    System.out.println(b2);
  }
}





Float.MAX_VALUE

  
public class Main {
  public static void main(String[] args) {
    System.out.println(Float.MIN_VALUE);
    System.out.println(Float.MAX_VALUE);
  }
}
/*
1.4E-45
3.4028235E38
*/





Float.MIN_VALUE

  

public class Main {
  public static void main(String[] args) {
    System.out.println(Float.MIN_VALUE);
    System.out.println(Float.MAX_VALUE);
  }
}
/*
1.4E-45
3.4028235E38
*/





Float: parseFloat(String s)

  
       
public class Main {
  public static void main(String[] args) {
    Float fObj1 = new Float("10.64");
    System.out.println(fObj1);
    Float fObj2 = Float.valueOf("10.76");
    System.out.println(fObj2);
    float f = Float.parseFloat("7.39");
    System.out.println(f);
  }
}
/*
10.64
10.76
7.39
*/





Float: shortValue()

  
    
    

public class Main {
  public static void main(String[] args) {
    Float fObj = new Float("10.50");
    byte b = fObj.byteValue();
    System.out.println(b);
    short s = fObj.shortValue();
    System.out.println(s);
    int i = fObj.intValue();
    System.out.println(i);
    float f = fObj.floatValue();
    System.out.println(f);
    double d = fObj.doubleValue();
    System.out.println(d);
  }
}





Float: toString()

  

public class Main {
  public static void main(String[] args) {
    Float fObj = new Float(10.25);
    String str = fObj.toString();
    System.out.println(str);
  }
}





Float: toString(float f)

  

public class Main {
  public static void main(String[] args) throws Exception {
    String str = Float.toString(0.3F);
  }
}





Float: valueOf(String stringValue)

  
/*
 * Output:
 
true
c
12
2
13245
12341234
11234.123
4.321324123412341E10

 */
public class MainClass {
  public static void main(String args[]) {
    Boolean bool = Boolean.valueOf("true");
    Character c = new Character("c");
    Byte b = Byte.valueOf("12");
    Short s = Short.valueOf("2");
    Integer i = Integer.valueOf("13245");
    Long l = Long.valueOf("12341234");
    Float f = Float.valueOf("11234.1234");
    Double d = Double.valueOf("43213241234.123412341234");
    System.out.println(bool);
    System.out.println(c);
    System.out.println(b);
    System.out.println(s);
    System.out.println(i);
    System.out.println(l);
    System.out.println(f);
    System.out.println(d);
  }
}





new Float(float value)

  
        
public class MainClass {
  public static void main(String[] args) {
    float f = -29.6f;
    Float f2 = new Float(f);
    System.out.println(f2.floatValue());
  }
}





new Float(String s)

  
    
    

public class Main {
  public static void main(String[] args) {
    Float fObj = new Float("10.50");
    byte b = fObj.byteValue();
    System.out.println(b);
    short s = fObj.shortValue();
    System.out.println(s);
    int i = fObj.intValue();
    System.out.println(i);
    float f = fObj.floatValue();
    System.out.println(f);
    double d = fObj.doubleValue();
    System.out.println(d);
  }
}