-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubString.java
More file actions
40 lines (26 loc) · 1.03 KB
/
Copy pathSubString.java
File metadata and controls
40 lines (26 loc) · 1.03 KB
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
35
36
37
38
39
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class SubString {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String S = in.next();
int start = in.nextInt();
int end = in.nextInt();
//make a special case when string length is either zero or one
//sub string starts from the index of the string you want to
//take and then ends with one more than the String you want to take
//leave the outer number
//method
//-Get the string
//-if the string is null throw exception of given null argument
//otherwise just print out str.substring(start, end);
if(S.equals(null)) {
throw new NullPointerException("You cannot find the substring of a null string");
}
System.out.println(S.substring(start, end));
return;
}
}