Ver Mensaje Individual
  #2 (permalink)  
Antiguo 12/05/2011, 10:20
Avatar de Heimish2000
Heimish2000
 
Fecha de Ingreso: enero-2011
Ubicación: Madrid
Mensajes: 844
Antigüedad: 13 años, 3 meses
Puntos: 89
Respuesta: mejora de funcion.

Excuse me for my english level, I know could be better

The first

if(bole==false)

have no sense because in this point bole ALWAYS will be false.

bol will be 0 if it's not a number, 1 if it's a integer and 3 if it's a double, is this what you want?

A better way to do the same with less code line is:

Código JAVA:
Ver original
  1. System.out.println(testNum("10.50"));
  2. ........
  3.    public static int testNum(String numero) {
  4.       int bol=0;  
  5.        int number ;
  6.        double num ;
  7.        try {
  8.             Integer.parseInt(numero);
  9.             bol=1;
  10.        }        
  11.        catch (NumberFormatException e) {
  12.           try {
  13.             Double.parseDouble(numero);
  14.             bol=3;
  15.           }
  16.           catch(NumberFormatException e) {
  17.                 e.printStackTrace();    
  18.           }
  19.        }
  20.        finally {
  21.         return bol;
  22.           }
  23.        }
  24.    }