recursions

recursions

Can somebody help me with these four questions. Please. i am learning recursions in Java.


Question1. Trying to find the value of result when its (5) from this code.

public int result(int n)
{
if (n==1)
return 2;
else
return 2 * result(n-1)


Question 2.
public int f (int k, int n)
{
if (n==k)
return k;
else
if (n > k)
return f(k, n-k);
else
return f(k-n, n)

}
I need the value returned by the call f(6,8)? and little bit of working for me to understand

question3.

i need to know what the method recur does in this code

public int recur(int[]x, int n)
{
int t;
if (n==1)
return x[0];
else
{
t=recur(x, n-1);
if (x[n-1];
else
return t;
}
}

Question 4

from the code below what will the value of z be when z = kwame( kwame (3) + kwame (4));

public int kwame(int x)
{
if (x==1 || x==3)
return x;
else
return x * kwame(x-1);
}


View Answers









Related Tutorials/Questions & Answers:
recursions in gui
recursions in gui  I need help in completing this. The art will be in contained in a JComponent that will reside in a JFrame and be drawn using simple drawing primitives and recursion to help divide the space into smaller
recursions - Java Beginners
recursions  Can somebody help me with these four questions. Please. i am learning recursions in Java. Question1. Trying to find the value of result when its (5) from this code. public int result(int n) { if (n==1
Advertisements

Ads