A voir également:
- Controle de type en java
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel - Télécharger - Jeux vidéo
- Eclipse java - Télécharger - Langages
- Java apk - Télécharger - Langages
- Waptrick java voiture - Télécharger - Jeux vidéo
9 réponses
Salut !
C'est peut-etre trop tard, mais avec ce bout de code c'est une solution :
try
{
lentree = Integer.parseInt(entree); // si String entree non num. >>> exception
}
catch (NumberFormatException f)
{
System.out.println(entree + " non numerique.");
return "";
}
C'est peut-etre trop tard, mais avec ce bout de code c'est une solution :
try
{
lentree = Integer.parseInt(entree); // si String entree non num. >>> exception
}
catch (NumberFormatException f)
{
System.out.println(entree + " non numerique.");
return "";
}
si c'est le cas
voici une méthode statique de la classe Integer par exemple
pour toutes les classes représentant une primitive numérique la même méthode existe
voici une méthode statique de la classe Integer par exemple
valueOf public static Integer valueOf(String s) throws NumberFormatExceptionReturns an Integer object holding the value of the specified String. The argument is interpreted as representing a signed decimal integer, exactly as if the argument were given to the parseInt(java.lang.String) method. The result is an Integer object that represents the integer value specified by the string. In other words, this method returns an Integer object equal to the value of: new Integer(Integer.parseInt(s)) Parameters: s - the string to be parsed. Returns: an Integer object holding the value represented by the string argument. Throws: NumberFormatException - if the string cannot be parsed as an integer.
pour toutes les classes représentant une primitive numérique la même méthode existe
il doit contenir un numérique (entier), mais l'utilisateur peut faire une faute de frappe et saisie une chaine de caractéres..!
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question