Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help writing this program in JAVA, this is an introductory java course, s

ID: 3811768 • Letter: I

Question

I need help writing this program in JAVA, this is an introductory java course, so if possible, keep it as basic/simple as possible while still following the instructions. The output should look like the sample execution at the end of the problem.

Write a program which reads a single word and displays all possible substrings of that word. You should display the substrings ordered by number of characters.

Input Validation:

None

Requirements:

Your input should be a single word of any number of characters.

The substrings must be listed according to length.

You may not use arrays or any other type of data structure.

Hints:

This program can be solved in less than 30 lines of code (possibly even less than 20). More than that, and you are probably overthinking your solution.

Sample Execution:

Explanation / Answer

PossibleSubStrings.java

import java.util.Scanner;

public class PossibleSubStrings {

   public static void main(String[] args) {
       String str = "";
       // Getting the String From the user.
       System.out.print("Enter the Word(Without Spaces) ::");
       Scanner sc = new Scanner(System.in);
       str = sc.next();
       System.out.println("The Possible SubStrings for '" + str + "' are:");
       // Calling the method
       genSubstrings(str);

   }

   // This function will generate all possible sub strings of user entered
   // string
   private static void genSubstrings(String str) {
       int len = str.length();
       int i, j, k = 1;

       while (true) {
           i = 0;
           j = k;
           while (true) {
               System.out.println(str.substring(i, j));
               i++;
               j++;
               if (j > str.length()) {
                   break;
               }
           }
           k++;
           if (k > str.length())
               break;
       }

   }

}

___________________

Output:

Enter the Word(Without Spaces) ::friday
The Possible SubStrings for 'friday' are:
f
r
i
d
a
y
fr
ri
id
da
ay
fri
rid
ida
day
frid
rida
iday
frida
riday
friday

______________Thank You