Question: fill in the missing methods using recursive 1- Complete the method, public boolean hasLessThan(int[ ] array, int value) and its recursive auxiliary method , inside

fill in the missing methods using recursive

1- Complete the method, public boolean hasLessThan(int[ ] array, int value) and its recursive auxiliary method, inside the RecursiveAssignment..java file. The method checks whether a given integer array contains a number smaller than a given integer value. Your method should stop immediately it finds a number smaller than value inside the array.

2- Write a recursive method to count the number of non-overlapping occurrences of a given sub-string in a given string. Example: In the string AAAAAAA there are 2 non-overlapping occurrences of the substring AAA; however there are 5 overlapping occurrences of AAA

3- complete the implementation of divide method using subtraction , so that no division operator is used For all these method

*1,2,3 same quetion

import java.util.Scanner; public class RecursiveAssignment{ public static void main(String args []){ Scanner stdin = new Scanner(System.in); System.out.println("Enter array size: "); int size = stdin.nextInt(); int[] array = new int[size]; for(int k = 0; k < size; k++){ array[k] = (int)(Math.random()*20+1); } System.out.print("The array is: "); for(int k = 0; k < size; k++) System.out.print(array[k] + " "); System.out.print(" Enter the integer to test: "); int value = stdin.nextInt(); if(hasLessThan(array, value)) System.out.println("THE ARRAY HAS AN ELEMENT LESS THAN " + value); else System.out.println("THE ARRAY HAS NO ELEMENT LESS THAN " + value); int x = 12, y=3; System.out.println(divide(x,y)); String str = "AABAABAABAA"; String subStr = "ABA"; System.out.println(countSubstringFrequency(str, subStr)); } public static boolean hasLessThan(int[] x, int value){ // call to the auxillary method to be implemented by students return hasLessThan(x,value,0); } // a private auxillary method to be implemented by students /*Complete the method, public boolean hasLessThan(int[ ] array, int value) and its recursive auxiliary method, inside the Lab05Task2.java file. The method checks whether a given integer array contains a number smaller than a given integer value. Your method should stop immediately it finds a number smaller than value inside the array. */ public static boolean hasLessThan(int[] x, int value, int start){ // Your code should be here } /* Students should implement a method that takes two numbers and check the result of x / y using the difference as follows x-y-y-y .. Unitl x reaches 0 you will count how many time you do subtraction. 10 - 2=8-2=6-2=4-2=2-2=0 */ public static int divide(int x, int y) { return divideTail(x, y, 0); } public static int divideTail(int x, int y, int res) { // Your code should be here } /* * Write a recursive method to count the number of non-overlapping occurrences of a given * sub-string in a given string. * Example: In the string AAAAAAA there are * 2 non-overlapping occurrences of the substring AAA; * however there are 5 overlapping occurrences of AAA */ public static int countSubstringFrequency(String str, String subStr) { return countSubstringFrequency(str, subStr,0, 0); } public static int countSubstringFrequency(String str, String subStr, int strt, int res) { // Your code should be here } } }

*** the output should look like this:

Enter array size: 5 The array is: 11 4 9 1 13 Enter the integer to test: 9 THE ARRAY HAS AN ELEMENT LESS THAN 9 The result of dividing 12 by 3 is 4 The times for existence of String ABA in String AABAABAABAA is 3 The times for existence of String ababa in String ababab is 1

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!