Answer to Question #259175 in Java | JSP | JSF for amr

Question #259175

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-31T00:14:43-0400
public class Main {
 static int S(int a, int n){
 if(a==0){
 System.out.print(0+"");
 return 0;
 
 }
 
 else if(a==1){
 return a * n;
 }
 
 else if(n==0){
 return a * 1;
 }
 else{
 System.out.print(a * S(a, n-1)+"");
 return a * S(a, n-1);
 }
 }
 public static void main(String[] args) {
     System.out.print("-2, 7, 52, 2702 ");
     S(-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

Amir
31.10.21, 07:27

tq so much this help me

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS