题解 | #The Biggest Water Problem#

The Biggest Water Problem

http://www.nowcoder.com/practice/435aa556e093463891f6da7d322140a4

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int res = 0;
        while(true) {
            int sum = 0;
            while (n > 0) {
                sum += n % 10;
                n /= 10;
            }
            res = sum;
            if (res < 10) break;
            n = res;
        }
        System.out.println(res);
    }
}

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务