Question number: 201512-1
Question name: the sum of digits
Time limit: 1.0s
Memory Limit: 256.0MB
Problem Description:
Problem description given a decimal integer n, the sum of the numbers of the output n. Input format Enter an integer n. Output format output An integer that represents the answer. Sample input 20151220 Sample output 13 sample description 20151220 The sum of the figures is 2+0+1+5+1+2+2+0=13. Evaluation use case size and convention all evaluation cases meet: 0≤n≤1000000000. Problem Solving: Implementing Code (Java):
1 PackageCcf_test2015_12;2 3 ImportJava.util.Scanner;4 5 Public classPositionsum {6 7 Public Static voidMain (string[] args) {8 9Scanner in =NewScanner (system.in);Ten One while(In.hasnext ()) { A - intnum =in.nextint (); - the intsum =getsum (num); - - System.out.println (sum); - + } - } + Public Static intGetsum (intnum) { A at intsum = 0; - - while(num > 0) { - - inttemp = num% 10; - inSum + =temp; - tonum = NUM/10; + - } the * returnsum; $ Panax Notoginseng } -}View Code
Operation Result:
CCF series of digits of the sum (201512-1)