Q:

Java Program to find all substrings of a string

0

Java Program to find all substrings of a string.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;
 
class demo1
{
   public static void main(String args[])
   {
      String string, sub;
      int i, c, length;
 
      Scanner in = new Scanner(System.in);
      System.out.println("Enter a string to print it's all substrings");
      string  = in.nextLine();
 
      length = string.length();   
 
      System.out.println("Substrings of ""+string+"" are:");
 
      for (c = 0; c < length; c++)
      {
         for(i = 1; i <= length - c; i++)
         {
            sub = string.substring(c, c+i);
            System.out.println(sub);
         }
      }
   }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now