演算法 -- 簡介

演算法

演算法簡介

複雜度理論

系統搜尋法

逼近法

隨機搜尋法

隨機統計法

最佳化

分配濃縮法

遞迴法

分割擊破法

動態規劃法

事前計算法

轉換領域法

轉換問題法

訊息

相關網站

參考文獻

最新修改

簡體版

English

字串轉整數

class Int 
{
    public static void main(String[] args) 
    {
        int i = parseInt("123");
        System.out.println("parseInt(123)="+i);
        String s = toString(392);
        System.out.println("toString(392)="+s);        
    }
 
    public static int parseInt(String s) 
    {
        int num = 0;
        for (int i=0; i<s.length(); i++) 
        {
            int ni = s.charAt(i)-'0';
            num = num*10 + ni;
        }
        return num;
    }
 
    public static String toString(int num) 
    {
        String rzStr = "";
        while (num > 0) 
        {
            int ni = num % 10;
            char ci = (char) (ni+'0');
            num = (num-ni) / 10;
            rzStr = ci+rzStr;
        }
        return rzStr;
    }
}

Facebook

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License