Related questions
Concept explainers
1. Create a java program from the supplied starter code: TestRecursion.java.
2. The array given can be used or you may input a different one and search for a value in it. YOU MUST
have a minimum of 11 elements in your array if you do not use mine.
3. Create a method bubleSortRecur() that performs a bubble sort using recursion. search. The method
accepts two parameters: an array of integers (any order) and the length. Print the original array, in the
main() method after the sort is called.
4. Call another method, BinarySearchRecur() that performs binary search recursively. It should take 4
parameters: a sorted array of integers, start position (index) and end position(index) of the array, and the
integer value to find. It should return the index of the element if found, if not then it should return -1.
Print the one integer being searched, and its index position from within the main() method
PLEASE ADD TO THE CODE GIVEN BELOW AND FOLLOW THE SLASHED LINES FOR ASSISTANCE
import java.util.Arrays;
public class TestRecursion {
public static void main(String[] args) {
int Xarr[] = new int[] {1,22,3,41,5,66,74,8,16,9,99,23,45,174,249,201,341,64,72,104};
System.out.println("original array: "+ Arrays.toString(Xarr));
bubbleSortRecur(Xarr,Xarr.length);
System.out.println("sorted array: "+Arrays.toString(Xarr));
int k= 0;
int zKey=66;
k = binarySearchRecur(Xarr,0,Xarr.length-1,zKey);
System.out.println("Search value: "+zKey+" found in position: "+k);
}
public static void bubbleSortRecur(int Xarr[], int n) {
//Recall from chapter9, when the first pass in the
//bubblesort is done, the highest value in the array
//is at the end. SO, you call itself with the same 'array'
//and one les for the length...
//base case is when the length, 'n' is equal 1.
}
public static int binarySearchRecur(int[] array, int start, int end, int target) {
//if the 'end' is less than the 'start' value
//you have reached the end of the array and
//not found the 'target' value.
//IF the target is the 'array[middle]' value
// then return the 'middle' as the value found to match
// the target (or zKey)
//if the target is less than the array element in middle
// the call yourself with 'start' and middle-1
// else call yourslef with 'middle+1' and 'end'
//remember you can call yourself with a 'return' statement since this
//method always returns an integer.
}
}
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images
- In Java please. Add comments too! thank you!arrow_forwardWrite a program named GradeStats.java then implement the following method: public static int[] gradeStats(int[] arr) It accepts int array representing test grades for CISY432 then calculates and returns the following grade statictics: highest, lowest, average, number of grades that are greater than or equal to 70, the number of grades that are less than 70 It returns these five numbers as an int array, and the 1st element is for highest, 2nd for lowest, 3rd for average 4th element for number of grades that are greater than or equal to 70 5th for the number of grades that are less than 70 For example. O Type here to search DELLarrow_forwardTask 2: Write a static method which takes an ArrayList of Strings and an integer and changes the ArrayList destructively to remove all Strings whose length is less than the integer argument. So if the integer argument is 4 and the ArrayList is: tomato cheese chips fruit butter tea buns pie The output tomato cheese chips fruit butter is:arrow_forward
- can you plz write it in java.util.scanner formarrow_forwardIntellij - Java Write a program which does the following: Create a class with the main() method. Take a string array input from the user in main() method. Note: Do not hardcode the string array in code. After the String array input loop, the array should be: words[] = {"today", "is", "a", "lovely", "spring","day", "not", "too", "hot", "not", "too", "cold"}; Print the contents of this array using Arrays.toString() method. Write a method called handleString() that performs the following: Takes a String[] array as method parameter (similar to main method). Loop through the array passed as parameter, and for each word in the array: If the length of the word is even, get the index of the last letter & print that index. Use length() and indexOf() String object methods. If the string length is odd, get the character at the 1st position in the string & print that letter. Use length() and charAt() String object methods.arrow_forwardIf a team is unable to complete all the points of work allocated for an iteration, the team should use the number of points that were completed as basis for the work for the next iteration. True/Falsearrow_forward
- Devise an algorithm that detects whether a given array is sorted into ascending order. Write a Java method thatimplements your algorithm. You can use your method to test whether a sort method has executed correctly. Ensure that your program has a test classarrow_forwardMethods Details: public static java.lang.StringBuffer[] getArrayStringsLongerThan(java.lang.StringBuffer[] array, int length) Returns a StringBuffer array with COPIES of StringBuffer objects in the array parameter that have a length greater than the length parameter. If no strings are found an empty array will be returned. Parameters: array - length - Returns: Throws:java.lang.IllegalArgumentException - When a null array parameter is providedarrow_forwardJava - Sort an Arrayarrow_forward
- For java. Refer to picture.arrow_forward2. Write a method that takes a rectangular two-dimensional array of type int and returns a valu of type int. The method returns the number of rows with negative sum. A row has a negative s if the sum of all its elements is less than 0. public static int countNegativeSum(int[][] in) Taken array Result 1 -3 17 -5 -5 14 -5 -2 30 -19 -8 -8 1 1 3 -1 -4 78 8 -3 -5 -1 -1 3 -4arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education