Showing posts with label Substrings of a String. Show all posts
Showing posts with label Substrings of a String. Show all posts

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);
            }
        }
    }
}