Statement Exercises 9

Source: Internet
Author: User

The value of the s=a+aa+aaa+aaaa+aa...a, and the sum of several numbers is controlled by the user.

1Scanner SC2 =NewScanner (system.in);2System.out.print ("Please Enter Number:");3         intnum2 =sc2.nextint ();4System.out.println ("Please enter several numbers to add:");5         intNUM3 =sc2.nextint ();6         intsum1 = 0;//Storage and7          for(inti = 1; I <= num3; i++) {8             DoubleA = 0.0;9             //Nth number = number of N-1 + number of displays multiplied by 10 n-1Ten              for(intj = 1; J <= I; J + +) { OneA = num2 * Math.pow (Ten, (j-1)) +A; A             } - System.out.println (a); -Sum1 + =A; the         } -System.out.println (num3 + "number added and =" + sum1);
1         intSum2=0;2          for(inti=1;i<=num3;i++){3             intNum4=0;4             //Number of Nth = number of n-1 multiplied by + + display5              for(intj=1;j<=i;j++){6num4=num4*10+num2;7             }8 System.out.println (NUM4);9sum2+=num4;Ten         } OneSystem.out.println (num3+ "number of added results =" +sum2);

Operation Result:

Statement Exercises 9

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.