28 lines
777 B
Java
28 lines
777 B
Java
|
Java programing code
|
||
|
import java.util.Scanner;
|
||
|
|
||
|
class SubstringsOfAString
|
||
|
{
|
||
|
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);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|