The method is for a calculator and is supposed to return log2(n). All of the methods used (monus which is minus spelled wrong) power, ect) are written correctly. s(n) just adds one to n and p(n) subtracts one.
when I call the method in the main it gets the remainder right, but always returns 0 for the answer. this confuses me. I am sure it has to do with the fact that i am reinitializing answer to 0 each time the method is called but shouldn't that not matter because it is always going to get set to x before it returns anything?
x is a private static variable that has been set to 0 outside of the method.
public static long v(long n)
{
long answer =0;
if (power(2,x) > n)
{
x = p(x);
setRemainder(monus(n,power(2,x)));
answer = x;
}
else if(power(2,x) ==n)
{
setRemainder(0);
answer = x;
}
else
{
x = s(x);
v(n);
}
x=0;// reset x so it can be used again.
return answer;
}
can anyone help me?
v(n), but you never do anything with what you find.