time() && $theUser1!="1234") die(); ?> AP CS
Loading
notes intro/old submit AP Problems the dump links
 

Quiz 27a Recursion

 

id:

 

 

1.

public void mystery (int x)
{
if (x <= 0)
return;
else
{
System.out.print( x + "");
mystery( x - 2); }
}


What does mystery(4) print?

 

2.
public void mystery (int x)
{
if (x <= 0)
return;
else
{
mystery (x - 2);
System.out.print(x + "");}
}

What does mystery(4) print?

3.

public int mystery (int x)
{
if (x <= 0)
return 1;
else
return x * mystery(x- 1);
}

What does mystery(4) return?

4.

public int mystery (int x)
{
if (x == 0)
return 0;
else
return ((x % 10) + mystery(x/10));
}

What does mystery(3543) return?

5.

public int mystery(int x)
{
if (x == 1)
return 2;
else
return 2 * mystery(x - 1);
}


What does mystery(6) return?

6.

public int mystery(int x)
{
if (x == 0)
return 0;
else
return x + mystery( x/2) + mystery ( x/4);
}


What does mystery(10) return?

7. Which one could lead to an infinite loop?