Question
Implement a class called SubstringTester that uses recursion to generate all substrings of a given String. For example, the substrings of the string Sluggo .
Implement a class called SubstringTester that uses recursion to generate all substrings of a given String. For example, the substrings of the string "Sluggo" .
You are not allowed to use any loops to build the substrings -- at least in your final product. You may, however, find it productive to solve the problem using loops first, and then translate to recursive code.
Implement methods in SubstringTester that will interact with the user, acquire a phrase and produce all of the substrings of that phrase. This class should
-Get a string from the user (possibly in main)
-Generate and display the substrings of the phrase
-Repeat the above two steps until the user chooses to quit
Here is the code I have so far where the input needs to be sluggo.
import java.util.Scanner;
public class SubstringTester
{
public static void main(String args[])
{
Scanner scanner = new Scanner(System.in);
System.out.print("Enter string: ");
String str = scanner.nextLine();
for(int i = 0; i < str.length(); i++)
{
for(int j = 0; j < str.length() - i; j++)
{
System.out.println(str.substring(i, str.length() - j));
}
}
}
}
I need the code to repeat this until the user chooses to quit.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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