Well, you've got three problems.
First, inside of the method, you're reassigning x
and n
. So, regardless of what you pass in, x
is always 2, and n
is always 3. This is the main cause of your infinite recursion - as far as the method is concerned, those values never update. Remove those assignments from your code.
Next, your base case is incorrect - you want to stop when n == 0
. Change your if
statement to reflect that.
Third, your recursive step is wrong. You want to call your next method with a reduction to n
, not to x
. It should read return x * exp(x, n-1);
instead.