import java.util.Scanner;
public class Substrings_String
{
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 ");
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);
}
}
}
}
OUTPUT ::
Enter a string
codez
Substrings of "codez" are :-
c
co
cod
code
codez
o
od
ode
odez
d
de
dez
e
ez
z
SOURCE CODE ::
OUTPUT ::
need an explanation for this answer? contact us directly to get an explanation for this answer