Java: Verificare che una stringa rappresenti un numero intero

public static boolean isNumeric(String s) {

boolean numerico = true;
char[] sequenza = s.toCharArray();

for (int i=0; i< sequenza.length; i++) {

try {

Integer.parseInt(Character.toString(sequenza[i]));

} catch (Exception e) {

numerico = false;

}

}

return numerico;
}

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>