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
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 } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started