Java recursion – exponentiation method

341 views Asked by At

I made the method exp in java but when I process the method I always get the same answer

public class Recursion {

    private double x;    
    private int n;

    // Method exp(x,n)

    public static double exp(double x,int n){

        if(n > 1){
         n = n-1;   
         x = x * x;
         exp(x,n);  
        }       
        else if (n == 1);
            return x;           
    }

    public static void main (String[]args){
        System.out.println(exp (2.5,4));
    }  
} 
0

There are 0 answers