All Substrings
abc
a
ab
abc
b
bc
c
import java.util.Scanner;
public class AllSubstring {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String st = s.nextLine();
printSubstrings(st);
}
public static void printSubstrings(String str) {
int l=str.length();
for(int i=0;i<l-1;i++)
{
for(int j=i;j<l;j++)
{
System.out.println(str.substring(i,j+1));
}
}
System.out.println(str.substring(l-1));
}
}
Comments
Post a Comment