Program to print all substrings of a given string | JavaScript 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
function printSubstrings ( str ) { var n = str . length ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i ; j < n ; j ++ ) { for ( var k = i ; k <= j ; k ++ ) { document . write ( str . charAt ( k ) ) ; } document . write ( " " ) ; } } } var str = " " ; printSubstrings ( str ) ;