Program to print all substrings of a given string | Java program for the above approach ; finding the length of the string ; outermost for loop this is for the selection of starting point ; 2 nd for loop is for selection of ending point ; 3 rd loop is for printing from starting point to ending point ; changing the line after printing from starting point to ending point ; Driver Code ; calling method for printing substring
import java . io . * ; class GFG { public static void printSubstrings ( String str ) { int n = str . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { for ( int k = i ; k <= j ; k ++ ) { System . out . print ( str . charAt ( k ) ) ; } System . out . println ( ) ; } } } public static void main ( String [ ] args ) { String str = " abcd " ; printSubstrings ( str ) ; } }