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.