1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Bas_tet [7]
2 years ago
9

What is output? public class MathRecursive { public static void myMathFunction(int a, int r, int counter) { int val; val = a*r;

System.out.print(val+" "); if (counter > 4) { System.out.print("End"); } else { myMathFunction(val, r, counter + 1); } } public static void main (String [] args) { int mainNum1 = 1; int mainNum2 = 2; int ctr = 0; myMathFunction(mainNum1, mainNum2, ctr); } }
a) 2 4 8 16 32 End
b) 2 2 2 2 2
c) 2 4 8 16 32 64 End
d) 2 4 8 16 32
Computers and Technology
1 answer:
ycow [4]2 years ago
3 0

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

You might be interested in
Explain the role of ICT in banks​
vladimir1956 [14]

Answer: ICT help banks improve the efficiency and effectiveness of services offered to customers, and enhances business processes, managerial decision making, and workgroup collaborations, which strengthens their competitive positions in rapidly changing and emerging economies.

Explanation: please give branliest I only need one more to make ace

7 0
2 years ago
Computer __ is any part of the computer that can be seen and touched​
iogann1982 [59]
Hardware
Answer. physical parts of computer which can be seen and touched are called Hardware.
3 0
2 years ago
Why does a print document need a higher raster effect setting ?​
mario62 [17]

Answer:

gives label artwork a professional, polished look.

Explanation:

6 0
3 years ago
Is MongoDB open source?
s2008m [1.1K]

Answer:

Yes

Explanation:

Check MongoDB on Github and you will see that it is open source.

7 0
3 years ago
قواعد البيانات الموزعه​
Monica [59]

Answer:

Translation : Distributed Databases

Explanation:

6 0
3 years ago
Other questions:
  • After a robbery, what is the purpose of conducting a neighborhood canvass?
    9·1 answer
  • An undesirable jagged appearance is referred to as
    7·2 answers
  • True or false: a cover letter accompanies a resume to showcase a job-seeker’s personal life
    6·2 answers
  • After placing her insertion point after Grandma’s Kitchen, order the steps Danica needs to follow to insert and format the regis
    8·2 answers
  • The ____ category of apps makes the computer easier for blind people to use.
    9·1 answer
  • Design a function that checks if a keyword exists in a given keyword tree and returns true if so and returns false otherwise. Af
    13·2 answers
  • What is the main advantage that a website builder offers for web development?
    9·2 answers
  • Your organization has 20 employees who need an accounting software update installed. Due to a miscommunication, the purchaser on
    6·1 answer
  • Name and define (or list the set that defines) three of the four common data types in programming
    12·1 answer
  • Is this code object-oriented, or is it procedural? what clues in the code itself did you use to determine what kind of code it i
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!