Write a program to find out all possible unique subString present in a given string



import java.util.Scanner;
 
public class  JavaInhouseSubstring
{
   public static void main(String args[])
   {
      String str, sub;
      int i, c, length;
 
     
      str  = "substring";
 
      length = str.length();
 
      System.out.println("Substrings of \""+str+"\" are :-");
 
      for( c = 0 ; c < length ; c++ )
      {
         for( i = 1 ; i <= length - c ; i++ )
         {
            sub = str.substring(c, c+i);
            System.out.print(sub+" ");
         }
      }
   }
}

OutPut: 

 subString present in a given string

Post a Comment