Java's Float took value, but expected answer is false!!


  • 0
    G

    My code is parsing value to Java's Float type. But test case is failing!

    class Solution {
        public boolean isNumber(String s) {
            try{
                Double.parseDouble(s.trim());
                return true;
            }
            catch(Exception e) {
                try {
                     Float.parseFloat(s.trim());
                     return true;
                }
                catch(Exception e1){
                     try{
                              Long.parseLong(s.trim());
                             return true;
                        }
                        catch(Exception e2){
                            try{
                                Integer.parseInt(s.trim());
                                return true;
                            }
                            catch(Exception e3){
                                return false;
                            }
                        }   
                }
            }
        }
    }
    
    Input:
    "959440.94f"
    Output:
    true
    Expected:
    false
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.