Question: Problem 1: (70 points) reate a program named RecursiveMethods.java and implement the following methods: C public static int smallest(int[] arr) (20 points) his method finds
Problem 1: (70 points)
reate a program named RecursiveMethods.java and implement the following methods:Cpublic static int smallest(int[] arr) (20 points)his method finds and returns the smallest value in the int array. (To get credit, it MUST be implemented as a recursive method. No credit if implemented with loop)Tpublic static int smallest(int[][] arr) (20 points)his method finds and returns the smallest value in the 2D int array. (To get credit, it MUST be implemented as a recursive method. No credit if implemented with loop)Tpublic static String repeat(String s, int n) (30 points)t accepts a string s and an integer n as parameters and that returns a String consisting of n copies of s. For example:I Call Value Returned repeat("hello", 3) "hellohellohello") "hi ho! hi ho! hi ho! hi ho! hi ho!repeat("this is fun", 1) "this is fun" repeat("wow", 0) "" repeat("hi ho! ", 5 "hould solve this problem by concatenating String objects using the + operator. String concatenation is an expensive operation, so it is best to minimize the number of concatenation operations you perform. For example, for the call repeat("foo", 500), it would be inefficient to perform 500 different concatenation operations to obtain the result. Most of the credit (25 points) will be awarded on the correctness of your solution independent of efficiency. The remaining credit (5 points) will be awarded based on your ability to minimize the number of concatenation operations performed. YouYou sr method should throw an IllegalArgumentException if passed any negative value for n. You are not allowed to construct any structured objects other than Strings (no array, List, Scanner, etc.) and you may not use any loops to solve this problem; you must use recursion. Then use the following code to test your methods (copy/paste to main method)int[] arr={2,4,3,89,0, -9};System.out.println(smallest(arr)); int[][] ar={{1,2,3,4,1,0},{0,-8,-90}};System.out.println(smallest(ar)); System.out.println(repeat(args[0], Integer.parseInt(args[1]) ));
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
