AP Computer Science Recursive Programing Help

AP Computer Science Recursive Programing Help




I really need help starting a Recursive program.



Heres the prompt:



Write a method that implements this definition of square numbers:

square(1) = 1

square(n) = square(n-1) + 2n - 1

** (n-1)^2 = n^2 - 2n -1 **



Write a program that implements the definition of a cube numbers.

(You will need the square method from above.)



I know that I have to write the square method before writing the cube, but I'm not really sure how to start a recursive program, whether it has a main or not, or any of that. I thought I knew what I was doing until I actually tried to type the program.



I also think, that I should use an if else loop.



This is what I have, it might be entirely wrong, i'm not really sure:



public class Cube

{

public static int cube(int c)

{

if(c == 1)

return 1;



else

return cube((n-1)*(n-1)*(n-1));

}

}



If you could tell me if I'm close and just give me a little hint or booster please because I really have to get this done.





No Answers Posted Yet.