Question: 1. What is the maximum value that can be returned by countSomething(n) for positive n, where the method countSomething is defined as follows: private int

1. What is the maximum value that can be returned by countSomething(n) for positive n, where the method countSomething is defined as follows: private int countSomething(int n)

{

int count = 0;

for (int i = 0; i < 100; i++)

{ count += n % 2;

n /= 2; n += 2;

}

return count;

}

2. Consider the following method mystery:

public String mystery(String str1, String str2)

{

if (str1.length() <= 1 || str2.length() <= 1)

return str2 + str1;

else

return mystery (str2.substring(1), str1.substring(1));

}

What will System.out.println(mystery("GOOD", "IDEA")); display?

3. The method fun is defined as follows:

public int fun(int n)

{

if (n == 1)

return 1;

else

{

int m = n/2;

return fun(m) + 2 * m * (n-m) + fun(n - m);

}

}

What does fun(5) return?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!