Write a recursive linear search method with a recursive step

Write a recursive linear search method with a recursive step that finds the last occurrence of a target in an array. Assume target is a String.public static String findLast(String s); *assume that all necessary files have already been imported.

Solution

Recursive method to find last occurance in an array: public static int findLastOccurance(Object[] items, Object target){ return findLastOccurance(items, target, items.length - 1); } /** Helper method for findLastOccurance(items, target). Recursively finds * the index of the last occurance of target in items[0...cur] */ private static int findLastOccurance(Object[] items, Object target, int cur){ if(curr == -1) //We went past the start - missed it. return -1; else if (target.equals(items[cur])) //Found it return cur; else return lineSearchLast(items, target, curr-1); //Work backwards }
 Write a recursive linear search method with a recursive step that finds the last occurrence of a target in an array. Assume target is a String.public static St

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site