Program to print all substrings of a given string | Java program to print all possible substrings of a given string ; Function to print all sub strings ; Pick starting point ; Pick ending point ; Print characters from current starting point to current ending point . ; Driver program to test above function
class GFG { static void subString ( char str [ ] , int n ) { for ( int len = 1 ; len <= n ; len ++ ) { for ( int i = 0 ; i <= n - len ; i ++ ) { int j = i + len - 1 ; for ( int k = i ; k <= j ; k ++ ) { System . out . print ( str [ k ] ) ; } System . out . println ( ) ; } } } public static void main ( String [ ] args ) { char str [ ] = { ' a ' , ' b ' , ' c ' } ; subString ( str , str . length ) ; } }