Question

You are given the following Java files: EvaluateExprission that you will use to add a method....

You are given the following Java files:

  • EvaluateExprission that you will use to add a method.

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

Homework Answers

Answer #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


Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
IN JAVA Complete the following program. Add codes in the main method to:1) call method average(double[]...
IN JAVA Complete the following program. Add codes in the main method to:1) call method average(double[] gpaarr ) to calculate the average of gpaArray; 2) add codes in the for loop to calculate sum 3) print the average . public class Test { public static void main (String args[]) { double[ ] gpaArray = { 2.5, 4.0, 3.8, 3.2, 2.9, 4.0 } ;   //add your codes here (you can put your codes in the Answer area with/without copying the original...
Using the attached files, TreeAssignment.java and IntTree.java Add to the methods in IntTree so that the...
Using the attached files, TreeAssignment.java and IntTree.java Add to the methods in IntTree so that the sumNodes methods returns the sum of all the integers in the tree. countLeftNodes should count up all the left children in the tree. Provided in IntTree.java is an example to help you called countEvenBranches which counts all the branches (nodes with children) with even values, but not leaves (nodes with no children) with even values. Both methods return an integer. The tree generated is...
java 1) Create a mutator method called setPosition that accepts one integer parameter. Update the position...
java 1) Create a mutator method called setPosition that accepts one integer parameter. Update the position variable by adding the position to the parameter variable. 2)debug the code public class food { public static void main(String[] args) { Fruits apple = new Fruits(20); // Write the statement to call the method that will increase the instance variable position by 6. Fruits.setPosition(6); apple.getPosition(); } }
Write a function (java static method) that computes the maximum of two integer. maxOfTwo(1, 2) →...
Write a function (java static method) that computes the maximum of two integer. maxOfTwo(1, 2) → 2 maxOfTwo(2, 1) → 2 maxOfTwo(1, 1) → 1 **(to start use): public int maxOfTwo(int a, int b) { And then complete the function (java static method)MaxOfThree so that it returns the maximum (highest) of the three int values passed as the parameters. maxOfThree(1, 2, 3) → 3 maxOfThree(0, 2, 1) → 2 maxOfThree(88, 4, 5) → 88 **(to start use): public int maxOfThree(int...
Java Code: Console IO Practice Exercise The purpose of this exercise is to practice console input...
Java Code: Console IO Practice Exercise The purpose of this exercise is to practice console input and output with the Java console. Setup: Create a class called ConsolePractice with a main method. Create a static field in your class that stores a scanner object. You will use this scanner for all user input. private static Scanner scanner = new Scanner(System.in); Part A: Create a static method called “divide”. Your method should do the following: Accept two integers as parameters, a...
You are given the following Java files: TestCharacterStack.java that contains class LLStack with class stackNode listed...
You are given the following Java files: TestCharacterStack.java that contains class LLStack with class stackNode listed as inner class.    You are given the following Java file: TestCharacterStack.java inside the class add the method below:         public boolean ParenthesesMatching (String text) takes a string text, and parenthesis whether its parenthesis are "balanced." Hint: for left parenthesis, push onto stack; for right parenthesis, pop from stack and check whether popped element matches right parenthesis, else return false. If returned value is...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
Please make a Java program that has a menu method and includes dialog boxes. The program...
Please make a Java program that has a menu method and includes dialog boxes. The program will call the proper method, but each method will be completed later. Your program will keep track of information for a Hospital. The program will be menu-driven. Your menu is to look something like the following: UPMC Medical Center Add/Modify Patient Information Add/Modify Physician Information Add/Modify Medical Information Hospital Report Section Exit the Medical System Please Make your selection > In this first phase,...
Java Programing Exercise #3: Write a Java class that implements a static method – SortNumbers(int… numbers)...
Java Programing Exercise #3: Write a Java class that implements a static method – SortNumbers(int… numbers) with variable number of arguments. The method should be called with different numbers of parameters and does arrange the numbers in descending order. Call the method within main method of the driver classand display the results.
Given the recursive method definition:    public static int recurMethod (int num) {         if (num...
Given the recursive method definition:    public static int recurMethod (int num) {         if (num > 10)             return num;         else             return num + recurMethod(num / 4);     } And the initial call: int answer = recurMethod(320); list the values that will be returned from each call to the previous call of recursMethod. Start with the last recursive call, and work backwards, with one space between each returned value, ending with the value returned to the original...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT