Write a program that will contain the following methods: printSub1, printSub2, printSub3, printSub4 – print all substrings of S using recursion. For example, if S = "abcd": printSub1 will print "a", "ab", "abc", "abcd", "b", "bc", "bcd", "c", "cd", "d" printSub2 will print "d", "cd", "bcd", "abcd", "c", "bc", "abc", "b", "ab", "a" printSub3 will print "a", "b", "c", "d", "ab", "bc", "cd", "abc", "bcd", "abcd" printSub4 will print "abcd", "bcd", "abc", "cd", "bc", "ab", "d", "c", "b", "a" Note that the actual output will not have quotation marks around the substrings. The substrings must print in the order shown for each method. You may only use these String methods in your work: length(), substring() Your main method in this program should provide an appropriate menu which allows the user the enter the string of their choice and pick any of the print substring options they want. write the methods recursively and in java
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 4 images
- I have to write a recursion method that finds the square root of a number by creating more accurate guesses each time. For some reason, my code is not returning any value and is not terminating at my base case. Can you help me see the issue I am having? import java.util.Scanner; /** * Greek's method to approximate the square root of a given number. */ public class SquareRootComputer { publicstaticvoidmain(String[] args) { // this is your tester // read a value from the user and print the results // along with expected value Scannerin=newScanner(System.in); System.out.println("Please input a value whose square root you would like determined: "); doublex=in.nextDouble(); //makes user input the value for x to determine it's square root. USE 91. System.out.println("The square root of "+x+"is: "+squareRoot(x)); System.out.println("Expected square root value of 91 is: 9.539392014."); in.close(); //closes the scanner to prevent any unintended errors. }…arrow_forwardThe nth harmonic number is defined non-recursively as: H(n)=1+1/2+1/3+1/4+...+1/n Come up with a recursive definition and use it to guide you to write a method definition for a double-valued method named “harmonic” that accepts an int parameter n and recursively calculates and returns the nth harmonic number. Write a test program that displays the harmonic numbers, H(n)=1,2,3,4...10arrow_forwardSolve in javaFXarrow_forward
- how can i solve this using java?arrow_forwardExercise-3: Write a recursive and iterative methods to convert a decimal number to its binary equivalent string. The iterative algorithm (in pseudo-code) for converting a decimal integer into a binary integer as follows: 1. If the integer is 0 or 1, its binary equivalent is 0 or 1. 2. If the integer is greater than or equal to 2 do the following: 3. Divide the integer by 2. 4. Separate the result into a quotient and remainder. 5. Divide the quotient again and repeat the process until the quotient is zero. 6. Write down all remainders in reverse order as a string. 7. This string is the binary equivalent of the given integer. // Recursive decimal to binary method public static String dec2binRecursive(int n) { if (n<2) return n+ " ". else return dec2binRecursive(n/2) + n%2; } a) Write the Complete program for above Recursive decimal to binary method Algorit b) Iterative decimal to binary methodarrow_forwardComplete the java program. Use two methods and make one of them recursivearrow_forward
- Write a recursive method called reverseString() that takes in a string as a parameter and returns the string in reversed order. The main method is provided to read a string from the user and call the reverseString() method. Use Java. Ex: If the input of the program is: Hello the reverseString() method returns and the program outputs: Reverse of "Hello" is "olleH". Ex: If the input of the program is: Hello, world! the reverseString() method returns and the program outputs: Reverse of "Hello, world!" is "!dlrow ,olleH". Hint: Move the first character to the end of the returning string and pass the remaining sub-string to the next reverseString() method call. import java.util.Scanner; public class LabProgram { /* TODO: Write recursive reverseString() method here. */public static void main(String[] args) {Scanner scnr = new Scanner(System.in);String input, result;input = scnr.nextLine();result = reverseString(input); System.out.printf("Reverse of \"%s\" is \"%s\".", input, result);}}arrow_forwardWrite a short recursive Java method that determines if a string s is a palindrome, that is, it is equal to its reverse. Examples of palindromes include 'racecar' and 'mom'. Test the method by asking the user to provide string entries to be checked. Hint: Check the equality of the first and last characters and recur (but be careful to return the correct value for both odd and even-length strings).arrow_forwardwrite a code in java (using recursion)arrow_forward
- A parking lot charges $3 per hour for the first 10 hours of a 24 hour period. There is no further charge starting at the 11th hour and ending at the 24th hour. The charge for a full 24 hour period is therefore $30. The same pattern applies for periods longer than 24 hours. Write a program to calculate the cost in dollars, given the number of hours that the parking lot was used. public class Parking { } public static void main(String[] args) { } // Change hours to get the answer for the those number of hours. int hours = 25; } int result = cost(hours); System.out.println(result); public static int cost(int hours) { int result = 0; // Write your code within the body of this method. return result;arrow_forward2arrow_forwardSolve in javaFXarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education