samedi 28 février 2015

Verify if String matches real number

I'm trying to verify if a String s match/is a real number. For that I created this method:



public static boolean Real(String s, int i) {

boolean resp = false;
//
if ( i == s.length() ) {
resp = true;
} else if ( s.charAt(i) >= '0' && s.charAt(i) <= '9' ) {
resp = Real(s, i + 1);
} else {
resp = false;
}
return resp;
}

public static boolean isReal(String s) {

return Real(s, 0);
}


But obviously it works only for round numbers. Can anybody give me a tip on how to do this?


P.S: I can only use s.charAt(int) e length() Java functions.


Aucun commentaire:

Enregistrer un commentaire