Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package guess;
- public class Check {
- public static boolean isNumeric(String str) {
- boolean ok = true;
- if (str.equals("")) {
- ok = false;
- } else {
- char[] sequenza = str.toCharArray(); //converte la stringa in un vettore di char
- for (int i = 0; i < sequenza.length; i++) { // controlla la natura integer di ogni carattere
- try { // e nel frattempo riconverte il vettore in stringa
- Integer.parseInt(Character.toString(sequenza[i]));
- } catch (NumberFormatException e) {
- ok = false; // ritorna false nel caso di lettere
- }
- }
- }
- return ok;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment