-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubstringExample.java
More file actions
28 lines (22 loc) · 833 Bytes
/
SubstringExample.java
File metadata and controls
28 lines (22 loc) · 833 Bytes
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
import java.util.Scanner;
public class SubstringExample {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Input the string
System.out.print("Enter a string: ");
String inputString = scanner.nextLine();
int length = inputString.length();
// Loop through the string to generate substrings
System.out.println("Substrings of the given string are:");
for (int i = 0; i < length; i++) {
for (int j = i + 1; j <= length; j++) {
// Extract the substring from index i to j manually
for (int k = i; k < j; k++) {
System.out.print(inputString.charAt(k));
}
System.out.println();
}
}
scanner.close();
}
}