0

Hi, I am working on a simple program where in one of the classes i have to add a static method which recursively divides a passed integer by 2 and returns a count of number of calls it takes to reach 1??I also have to Add a static method called "sumofcharacters" to my Recursion class that recursively sums the character values in a passed string and returns the sum. Can some one help me with how to return a count of number of calls and method that computes sums of the character values in a passed string...

this is what i have so far....

public static int intlog2(int n) {
if (n == 1)
return 1;
else
return intlog2(n/2);
}

Thanks

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by DarkLightning7
0

simply make a loop and count the number of times the loop executes like this:

int count = 0;
while([B]varname[/B] != 1){
[B]varname[/B] = [B]varname[/B] / 2;
count++;
{
return count;

you can change the items in bold.

In order to add chars you need to convert them to int values.

char character1 = 'c';
int charValue1 = (int)character1;

then simply add them together.


hope this helps. ( ;
if any thing does not work please tell me I don't have access to a java development environment at the moment.

Edited by DarkLightning7: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.