Question: import java.util.Scanner; /** * * This program repeatedly ask the user for a word and will generate * all the substrings of a given word,

import java.util.Scanner; /** * * This program repeatedly ask the user for a word and will generate * all the substrings of a given word, in increasing order of substring length. */ public class hw4_task6 { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.printf("This program will generate all the substrings of a " + "given word, in increasing order of substring length. "); System.out.printf(" Please enter a word or q to quit: "); String userWord = in.next(); while (!userWord.equals("q")){ // This code does not run now. // You must write the printSubstrings method. printSubstrings(userWord); System.out.printf(" Please enter a word or q to quit: "); userWord = in.next(); } System.out.println(" Bye "); } // Implement the printSubstrings method here. }import java.util.Scanner; /** * * This program repeatedly ask the user for 

Task 6 (35 pts) - Print all substrings File: hw4 task6.iava Adapted from book problem P4.12, page 190 In the program hw4 task6.java implement the printSubstrings method. It will take as argument one string and print all its substrings, sorted by length as shown in the sample run below. 1. Use string formatting to make the cells aligned. In particular each cell is as wide as the length of the string plus 2 2. You must match the sample output completely (same number of spaces, dashed lines..) Hints 1. Use nested loops to produce the indexes needed to generate the substrings you want. With those indexes, use the substring method to create the substring 2. First try to produce the substrings on a specific row. (See the pattern of the indexes that give all the substrings of a specific length 3. Next, see how you can use an outer loop to make the above code (that produces one row) repeat 4. In order to be able to produce this formatting, you must BUILD the formatting string. For example, for "cat", instead of hardcoding, "%3s", you must find the length of string and use string concatenation. That way, when a longer string is given, it will build the formatting string with the correct string length Sample run: This program will generate all the substrings of a given word, in increasing order of substring length. Please enter a word or q to quit: cat ca cat Please enter a word or q to quit: elephant ep an ele eph han | elep leph ephaphanhant I | eleph lepha eph phant | elephalephan ephant I | elephan lephant | | elephant | Please enter a word or q to quit: barn

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!