Java code


  • 0
    I

    int sum;
    do{
    sum = 0;
    while(num>0){
    sum += num%10;
    num /= 10;
    }
    num = sum;
    }while(sum>=10);//不管,先执行一次,得到一个sum.再判断,如果符合了就退出,否则,继续执行
    return sum;


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.