Question 1106: Sum of numbers
Time Limit: 1 second memory limit: 32 MB Special Judgment: No submitted: 873 solution: 618
Description:
For a given positive integer N, calculate the sum of all digits in decimal form and the sum of all digits in the square.
Input:
Each row of input data includes a positive integer N (0 <n <40000). If n = 0, the input ends and is not calculated.
Output:
For each input data, calculate the sum of its numbers and the sum of its square values, and output them in a row separated by a space,
Do not have spaces at the end of the line.
Sample input:
4
12
97
39999
0
Sample output:
4 7
3 9
16 22
39 36
Package: answers questions from Jilin University. 2nd question _ number sum; import Java. io. bufferedinputstream; import Java. math. biginteger; import Java. util. extends; public class main {/*** @ Param ARGs */public static void main (string [] ARGs) {using CIN = new using (New bufferedinputstream (system. in); biginteger = NULL; int temp, count1, count2; string STR = NULL; while (CIN. hasnext () {count1 = 0; count2 = 0; temp = cin. nextint (); If (temp = 0) {return;} else {STR = temp + ""; for (INT I = 0; I <Str. length (); I ++) {count1 + = Str. charat (I)-48;} // square biginteger = biginteger. valueof (temp); biginteger = biginteger. multiply (biginteger); STR = biginteger. tostring (). trim (); For (INT I = 0; I <Str. length (); I ++) {count2 + = Str. charat (I)-48;} system. out. println (count1 + "" + count2 );}}}}