Answer to Question #259019 in Java | JSP | JSF for jane

Question #259019

Write a recursive method named series (int a, int n) that takes as a parameter an integer that may  compute the following series: 

-2, 7, 52, 2702… if a = -2 and n = 4 


Then, write a full program to solve the above problem using recursion. 




1
Expert's answer
2021-10-30T23:55:24-0400


package geometric;




public class Geometric {


    static int series(int a, int n){
        if(a==0){
            System.out.println(0);
            return 0;
            
        }
        
        else if(a==1){
            return a * n;
        }
        
        else if(n==0){
            return a * 1;
        }
        else{
            System.out.println(a * series(a, n-1));
            return a * series(a, n-1);
        }
    }
    public static void main(String[] args) {
        series(-2,4);
    }
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS