Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one.
Update (2015-02-10): The signature of the C++ function had been updated. If you still see your function signature accepts a const char * argument, please click the reload button to reset your code definition.
Solution
publicclassSolution {publicbooleanisNumber(String s) {int len =s.length();int i =0, e = len -1;while (i <= e &&Character.isWhitespace(s.charAt(i))) i++;if (i > len -1) returnfalse;while (e >= i &&Character.isWhitespace(s.charAt(e))) e--;// skip leading +/-if (s.charAt(i) =='+'||s.charAt(i) =='-') i++;boolean num =false; // is a digitboolean dot =false; // is a '.'boolean exp =false; // is a 'e'while (i <= e) {char c =s.charAt(i);if (Character.isDigit(c)) { num =true; }elseif (c =='.') {if(exp || dot) returnfalse; dot =true; }elseif (c =='e') {if(exp || num ==false) returnfalse; exp =true; num =false; }elseif (c =='+'|| c =='-') {if (s.charAt(i -1) !='e') returnfalse; }else {returnfalse; } i++; }return num; }}