-
Notifications
You must be signed in to change notification settings - Fork 0
/
SubString.java
34 lines (29 loc) · 809 Bytes
/
SubString.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
For a given input string(str), write a function to print all the possible substrings.
A substring is a contiguous sequence of characters within a string.
Example: "cod" is a substring of "coding". Whereas "cdng" is not as the characters taken are not contiguous
imput:
co
output:
c
co
o
*/
import java.util.* ;
import java.io.*;
import java.util.Scanner;
class Solution {
static void printSubstrings(String input) {
// Write your code here
for(int i=0; i<input.length();i++){
for(int j =i+1; j<= input.length();j++){
System.out.println(input.substring(i,j));
}
}
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
printSubstrings(input);
}
}