Reanswer questions of Jilin University-sum of numbers

Source: Internet
Author: User

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 );}}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.