Méthode Java Integer class floatValue() avec exemple
Méthode floatValue() de classe entière
- méthode floatValue() est disponible dans le package java.lang.
- méthode floatValue() est utilisé pour renvoyer la valeur indiquée par cet objet Integer converti en type float (par cast).
- méthode floatValue() est une méthode non statique, elle est accessible uniquement avec l'objet de classe et si nous essayons d'accéder à la méthode avec le nom de la classe, nous obtiendrons une erreur.
- méthode floatValue() ne lève pas d'exception au moment de la conversion de Integer en float.
Syntaxe :
public float floatValue();
Paramètre(s) :
- Il n'accepte aucun paramètre.
Valeur renvoyée :
Le type de retour de cette méthode est float, elle retourne une valeur convertie (de type Integer à float) représentée par cet objet Integer.
Exemple :
// Java program to demonstrate the example // of floatValue() method of Integer class public class FloatValueOfIntegerClass { public static void main(String[] args) { // Variables initialization int i1 = 30; int i2 = 40;; // It returns an integer value denoted by this Integer ob1 object // and converted to a float by calling ob1.floatValue() Integer ob1 = new Integer(i1); // Display ob1 result System.out.println("ob1.floatValue(): " + ob1.floatValue()); // It returns an integer value denoted by this Integer ob2 object // and converted to a float by calling ob2.floatValue() Integer ob2 = new Integer(i2); // Display ob2 result System.out.println("ob2.floatValue(): " + ob2.floatValue()); } }
Sortie
ob1.floatValue(): 30.0 ob2.floatValue(): 40.0