I came across it as a problem to solve. What kind of limitations are there?
public long parseLong(String number)
{
long n=0;
if(number==null || number.isEmpty())
{
System.out.println("Number is null or empty");
return n;
}
boolean isNegative = false;
if(number.charAt(0)=='-')
{
isNegative=true;
}
else {
n = getValue(number.charAt(0));
}
for(int i=1;i<number.length();i++)
{
n = n*10 + getValue(number.charAt(i));
}
return isNegative ? (-1*n) : n;
}
public int getValue(char ch)
{
int value = ch;
if(value<'0' || value>'9')
{
throw new NumberFormatException();
}
return value-'0';
}