Méthode intValue() de la classe Java Float avec exemple
Méthode intValue() de la classe flottante
- méthode intValue() est disponible dans le package java.lang.
- méthode intValue() est utilisé pour renvoyer la valeur indiquée par cet objet Float converti en type int (par cast).
- méthode intValue() est une méthode non statique, elle est accessible uniquement avec un 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 intValue() ne lève pas d'exception au moment de la conversion de float en int.
Syntaxe :
public int intValue();
Paramètre(s) :
- Il n'accepte aucun paramètre.
Valeur renvoyée :
Le type de retour de cette méthode est int, elle retourne une valeur convertie (du type float en int) représentée par cet objet Float.
Exemple :
// Java program to demonstrate the example // of intValue() method of Float class public class IntValueOfFloatClass { public static void main(String[] args) { // Variables initialization float value1 = 10.20f; float value2 = 20.20f; // It returns float value denoted by this Float f1 object // and converted to a int by calling f1.intValue() Float f1 = new Float(value1); // Display f1 result System.out.println("f1.intValue(): " + f1.intValue()); // It returns float value denoted by this float f2 object // and converted to a int by calling f2.intValue() Float f2 = new Float(value2); // Display f2 result System.out.println("f2.intValue(): " + f2.intValue()); } }
Sortie
f1.intValue(): 10 f2.intValue(): 20