|
hello, i am preparing for java exam. i am going this exercise, i get confuse with this one. let me know if you have any idea.
void quiz(int i)
{
if (i > 1)
{ quiz(i / 2);
quiz(i / 2);
}
System.out.print("*");
}
How many asterisks are printed by the method call quiz(5)?
A. 3
B. 4
C. 7
D. 8
E. Some other number
|
|
|
Let's try it
class Quiz
{
public static void main(String[] args)
{
quiz(5);
}
private static void quiz(int n)
{
if(n > 1)
quiz(n/2);
System.out.print("*");
}
}
Output:
C:\jexp>java Quiz
***
|
|
|
|
|
hi, thanks for your responce.i have one question. when a method call is executed, which information is not saved in the activation record? formal parameters or local variables?
|
|
|
|
|
|
|
|