-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram73.java
More file actions
22 lines (18 loc) · 785 Bytes
/
Program73.java
File metadata and controls
22 lines (18 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.Scanner;
class SubstringExample{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a string: ");
String originalString = input.nextLine();
System.out.print("Enter the starting position: ");
int startIndex = input.nextInt();
System.out.print("Enter the ending position: ");
int endIndex = input.nextInt();
if (startIndex < 0 || endIndex > originalString.length() || startIndex > endIndex) {
System.out.println("Invalid input. Please check the positions.");
} else {
String substring = originalString.substring(startIndex, endIndex);
System.out.println("Substring: " + substring);
}
}
}