例如  String num="12345"; 

解决方案 »

  1.   

        int string2Int(String s) throws NumberFormatException
        {
    if(s==null)
    throw new NumberFormatException();
    int index=1;
    int result=0;
    int len=s.length();
    char zero='0';
    for(int i=len;i>0;i--)
    {
    char c=s.charAt(i-1);
    int digit=c-zero;
    if(digit<0||digit>9)
    {
    throw new NumberFormatException(); }
    result = result+ digit*index;
    index = index*10;
    }
    return result;
    }
      

  2.   

    number = 个位数*1+ 10位数*10 +百位数*100+...
    String data;
    个位数=data.charAt(data.length()-1);
    10位数=data.charAt(data.length()-1);
    ...位数=data.charAt(0);正常情况下data.charAt(n)应该 大于等于'0',小于等于'9',否则不是正确的数字