# Geometric Progression using Recursion (Java)

I have an assignment for class where I need to write a method which calculates a Geometric progression for n integers using recursion.

The value of n is received from the user.

public static float Geometric(float n)

{

if(n==0)

return 1;

else

{

if(n == 1)

System.out.println(n);

else

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

}

}

The code works fine, until the value of n exceeds 34. Then, the method starts returning wrong answers. I'm assuming it has to do with the maximum value that a float can hold.

Is there a way to calculate/store values that exceed the maximum value of...

By: StackOverFlow - Tuesday, 6 November

# Related Posts

- Older News
- Save recursion values for further calculations StackOverFlow (Yesterday) - Hello :) I have to find out the different combinations for an assignment (how to combine spices with different meals). I used a recursion to get the solution. The recursion...