LinkedIn interview question

Write a function to check if a given string is a number.

Interview Answer

Anonymous

23 Jan 2015

My code for this question in Java. I assumed number as anything that can be put into an operation in a calculator. if (str == null){ return false; } char[] c = str.toCharArray(); if (c.length() 1 || toTest.equals("-.") || ((isNegative == true || decCount > 0) && c.length ==1)){ return false; } return true;