Tuesday, May 27, 2014

Substrings of a String

import java.util.Scanner;

public class SubStringOfString{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the string for which you want substring: ");
        String s = in.next();
       
        int l = s.length();
        String sub = "";
        for(int i=0; i<l; i++){
            for(int j=i; j<l; j++){
                sub = s.substring(i,j+1);
                System.out.println(sub);
            }
        }
    }
}

No comments:

Post a Comment