Consider the following method: public static int f(int a) { if (a < 0) { return -1;

Question:

Consider the following method:

public static int f(int a)
{
if (a < 0) { return -1; }
int n = a;
while (n > 0)
{

if (n % 2 == 0) // n is even
{
n = n / 2;
}
else if (n == 1) { return 1; }
else { n = 3 * n + 1; }
}
return 0;
}
Perform traces of the computations f(-1), f(0), f(1), f(2), f(10), and f(100).

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: