Controle de type en java

s'il vous plai, est c qu'il y a une fonction java qui faire le controle sur la valeur d'un champ qui doit etre un numérique !!
Configuration: Windows XP
Internet Explorer 6.0

9 réponses

  1. 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 "";
    }
    1
    1. Modérateur
      salut

      certainement mais que contient ton champ ???

      un chaine de caratère ?
      0
      1. Modérateur
        si c'est le cas

        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

        0
        1. il doit contenir un numérique (entier), mais l'utilisateur peut faire une faute de frappe et saisie une chaine de caractéres..!
          0
          1. Modérateur
            donc tu peux tester avec cette méthode sans problème
            0
            1. Modérateur
              http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Integer.html
              0
              1. tu peut me donner un exemple complet en francais !
                0
                1. Modérateur
                  ben c'est la documentation java officielle

                  euh? j'ai jamais travaillé (ni trouvé d'ailleurs) l'équivalent en français
                  0