Question: Java code please import java.util.Queue; import java.util.Stack; public class Recursion { /** * Write a recursive function that finds the index of s2 in s1.

Java code please

import java.util.Queue; import java.util.Stack;

public class Recursion {

/** * Write a recursive function that finds the index of s2 in s1. Do not use any * string functions except for .length(), .equals(), and .substring(). Do not use * any loops, or any data structures. * @param s1 * @param s2 * @return Returns the index of the first time that * s2 appears in s1 or -1 if s2 is not contained * in s1. */ public static int indexOf(String s1, String s2) { return -1; }

/** * Write a recursive function that removes the first k even numbers * from the stack. If there are less than k even elements in the stack, * just remove all even elements. Do not use any loops or data structures * other than the stack passed in as a parameter. * @param stack * @param k * @return Returns the number of elements removed from the stack. */here first k means k elements from top public static int removeEvenNumbers(Stack stack, int k) { return 0; }

/** * Write a recursive function that accepts an integer and * returns a new number containing only the even digits, in the same * order. If there are no even digits, return 0. Your function should * work for positive or negative numbers. You are NOT allowed * to use any data structures. You are not allowed to use Strings to * solve this problem either. * @param n * @return The input with only the even digits remaining in the same * order. */ public static int evenDigits(int n) { return 0; }

/** * Write a recursive function that evaluates a Queue as a mathematical * expression. This queue can have any of the following characters: * { '(', ')', '+', '*'} or any single digit number. Evaluate this expression and * return the result. For example, for the expression: * "(((1+2)*(3+1))+(1*(2+2)))", each of these characters would be in the * q. As you recursively evaluate characters from the expression, you will * remove the characters from the q. After evaluating the above expression, * you should return 16. You are guaranteed that there are NO two digit numbers, * and that the expression is well formed (parenthesis match, etc...). Do not use any * loops. Do not use any data structures besides the q passed in as a parameter. * @param q * @return The result of the mathematical expression. */ public static int evaluate(Queue q) { return 0; }

/** * Write a recursive function that accepts a stack of integers and * replaces each int with two copies of that integer. For example, * calling repeatStack and passing in a stack of { 1, 2, 3} would change * the stack to hold { 1, 1, 2, 2, 3, 3}. Do not use any loops. Do not use * any data structures other than the stack passed in as a parameter. * @param stack */ public static void repeatStack(Stack stack) {}

/** * Write a recursive function that accepts a Queue. It * should change every int in this queue to be double its original * value. You may NOT use loops or any other data structures besides * the queue passed in as a parameter. You may use a helper function. * @param q */ public static void doubleElements(Queue q) {}

}

please help, I will give you a thumb up

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!