258. Add Digits

    /*
     * 258. Add Digits
     * 2016-6-21 by Mingyang
     */
    public static int addDigits(int num) {
          if(num<=9)
            return num;
           while(num>9){
              int temp=num;
              int res=0;
              while(temp>0){
                  res+=temp%10;
                  temp=temp/10;
              }
              num=res;
           }
           return num;
        }
原文地址:https://www.cnblogs.com/zmyvszk/p/5606185.html