Answer:
The output of the program is:
2 4 8 16 32 64 End
Explanation:
See attachment for proper presentation of the program
The program uses recursion to determine its operations and outputs.
The function is defined as: myMathFunction(int a, int r, int counter)
It initially gets the following as its input from the main method
a= 1; r = 2; counter = 0
Its operation goes thus:
val = a*r; 1 * 2 = 2
Print val; Prints 2
if (counter > 4) { System.out.print("End"); } : Not true
else { myMathFunction(val, r, counter + 1); }: True
The value of counter is incremented by 1 and the function gets the following values:
a= 2; r = 2; counter = 1
val = a*r; 2 * 2 = 4
Print val; Prints 4
else { myMathFunction(val, r, counter + 1); }: True
The value of counter is incremented by 1 and the function gets the following values:
a= 4; r = 2; counter = 2
val = a*r; 4 * 2 = 8
Print val; Prints 8
else { myMathFunction(val, r, counter + 1); }: True
The value of counter is incremented by 1 and the function gets the following values:
a= 8; r = 2; counter = 3
val = a*r; 8 * 2 = 16
Print val; Prints 16
else { myMathFunction(val, r, counter + 1); }: True
The value of counter is incremented by 1 and the function gets the following values:
a= 16; r = 2; counter = 4
val = a*r; 16 * 2 = 32
Print val; Prints 32
else { myMathFunction(val, r, counter + 1); }: True
The value of counter is incremented by 1 and the function gets the following values:
a= 32; r = 2; counter = 5
val = a*r; 32 * 2 = 64
Print val; Prints 64
if (counter > 4) { System.out.print("End"); } : True
<em>This prints "End"</em>
So; the output of the program is:
2 4 8 16 32 64 End