You are given the following Java files:
In EvaluateExprission.java write a recursive method
public static int EvaluateE (int x, int y)
The method should evaluate the expression bellow and take the values x, y from the user.
Update the main to call EvaluateE method properly .
E = xy +x* (x-1)(y-1) +x* (x-2)(y-2) + . . . +1
import java.util.*;
public class EvaluateExprission
{
//recursive method to calculate the sum of the series
public static int EvaluateE (int x, int y)
{
//base condition
if(x*y < 1)
return 0;
//recursive call
return x*y + x * EvaluateE(x-1, y-1);
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//get user input
System.out.println("Enter the value of x and
y:");
int x = sc.nextInt();
int y = sc.nextInt();
//method calline
int E = EvaluateE(x, y);
//display the result
System.out.println("The sum of the
series is = "+E);
}
}
OUTPUT:
Enter the value of x and y:
2 2
The sum of the series is = 6
Get Answers For Free
Most questions answered within 1 hours.