I'm trying to check if a String x matches a real number (any). For this I created the following 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 this method is only for integers , not real . Could you suggest me how to do this verification?
Q: I can only use the functions: s.charAt(int)
and length()
of Java.