258. Add Digits

public class Solution {
    public int addDigits(int num) {
        int temp=num;
        while(temp/10!=0)
        {
            int res=temp%10;
            while(temp/10!=0)
            {
                temp/=10;
                res+=temp%10;
            }
            temp=res;
        }
        
        return temp;
    }
}

 

posted @ 2016-07-12 17:33  阿怪123  阅读(104)  评论(0编辑  收藏  举报