Print all substring of given string in java.

 import java.util.*;

public class Main

{

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("enter string=");

String s=sc.next();

int n=s.length();

for(int i=0; i<n; i++){

      for(int j=i+1; j<=n; j++){

            System.out.print(s.substring(i,j)+" ");

      }

      System.out.println();

}

}

}

output->

enter string=

rohan

r ro roh roha rohan 

o oh oha ohan 

h ha han 

a an 


Comments

Popular posts from this blog

Introduction of java Programming language.

Stack data structure.