Example taken from <C language example development Daquan>
Question: calculate a + AA + AAA +... + Aaaa... A (x A), where the values of a and X are input from the keyboard, for example, input a = 1, x = 3, equivalent to 1 + 11 + 111
Note:
1. Find the implementation rule of AAAA.
2. Find the Implementation of A + AA + AAA.
Package COM. jue. addition; public class testaddition {/*** @ Param ARGs */public static void main (string [] ARGs) {// todo auto-generated method stubsystem. out. println (getdatasum (2, 5);}/*** calculation result, for example: result of 2 + 22 + 222 + 2222 + 22222 */static int getdatasum (int A, int X) {int sum = 0; For (INT I = 1; I <= x; I ++) {sum + = getdata (A, I) ;}return sum ;}/ *** calculates a number composed of X lengths of, for example, the number composed of five 2 is 22222 */Private Static int getdata (int A, int X) {int sum = 0; For (INT I = 1; I <= X; I ++) {sum + = A * getmultiplier (I);} return sum;}/*** get a multiple, for example, in 2*1000 = 2000, 1000 is the multiple ** @ Param x * @ return multiple */Private Static int getmultiplier (int x) {If (x = 0) {return 0 ;}if (x = 1) {return 1 ;}return 10 * getmultiplier (X-1 );}}