Title: The value of S=A+AA+AAA+AAAA+AA...A, where a is a number.

Source: Internet
Author: User

First, the first kind of wording

 PackageCom.pb.demo1;ImportJava.util.Scanner;/*** Title: Find the value of S=A+AA+AAA+AAAA+AA...A, where a is a number. For example 2+22+222+2222+22222 (a total of 5 numbers are added at this time), * A and the number of digits of the cumulative number are received from the keyboard. Program Analysis: * 1, receive a number from the keyboard input (the number can only be between 1-9) * 2, receive a number to indicate the number of digits of the accumulation of * 3. For example, enter a 4 (the number of digits in the accumulated number), and the value of keyboard input A is 5:s=5+55+555+5555 4. Enter a 5:s=a+aa+a AA+AAAA+AAAAA * First notation*/ Public classDemo2 { Public Static voidMain (string[] args) {//declaring a value a variable of a scannerScanner input =NewScanner (system.in); System.out.println ("Please enter the number of participating operations 1-9:"); intn=Input.nextint (); System.out.println ("Please enter the number of operations:"); intnum=Input.nextint (); //define the intermediate variable for Each loop to calculate the number of each                Doublenums=0.0; //finally listen to the sum                Doublesum=0.0;  for(inti = 0; i < num; i++) {                    //each time the number plus n is the value of the new nnums+=N; //sumsum+=Nums; //the value of n increases by one bit at a timeN=n*10; System.out.println ("The number of operations per operation is:" +nums); } System.out.println ("The final sum is:" +sum); }}

Ii. the second type of wording
 PackageCom.pb.demo1;ImportJava.util.Scanner;/*** Title: Find the value of S=A+AA+AAA+AAAA+AA...A, where a is a number. For example 2+22+222+2222+22222 (a total of 5 numbers are added at this time), * A and the number of digits of the cumulative number are received from the keyboard. Program Analysis: * 1, receive a number from the keyboard input (the number can only be between 1-9) * 2, receive a number to indicate the number of digits of the accumulation of * 3. For example, enter a 4 (the number of digits in the accumulated number), and the value of keyboard input A is 5:s=5+55+555+5555 4. Enter a 5:s=a+aa+a AA+AAAA+AAAAA * Second notation*/ Public classDemo3 { Public Static voidMain (string[] args) {//declaring a value a variable of a scannerScanner input =NewScanner (system.in); System.out.println ("Please enter the number of participating operations 1-9:"); intn=Input.nextint (); System.out.println ("Please enter the number of operations:"); intnum=Input.nextint (); //define the intermediate variable for Each loop to calculate the number of each        Doublenums=0.0; //finally listen to the sum        Doublesum=0.0;  for(inti = 0; i < num; i++) {            //use the Power function of mathematics to calculateNums+=math.pow (Ten, i) *N; Sum+=Nums; System.out.println ("The number of operations per operation is:" +nums); } System.out.println ("The final sum is:" +sum); }}

Title: The value of S=A+AA+AAA+AAAA+AA...A, where a is a number.

Related Article

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.