216k views
10 votes
Language: JAVA

Given the following method:

public void call(int k)
{
if (k > 1)
{
call(k - 2);
call(k - 1);
System.out.print(k);
}
}

What will be the output by the command call(5);?

a) 3 4 5
b) 2 2 3 4 5
c) 2 3 2 3 4 5
d) 2 3 2 2 3 4 5
e) 2 3 2 3 2 3 4 5

Please explain this if possible--thanks in advance!

1 Answer

5 votes

Answer:

B

Step-by-step explanation:

I believe that would be the answer from the algorithm you used in the call function.

Correct me if I am wrong

User Waldy
by
4.0k points