-
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) · 942 Bytes
/
Substring.java
File metadata and controls
40 lines (26 loc) · 942 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
29
30
31
32
33
34
35
36
37
38
39
40
import java.util.Scanner;
public class Substring{
public static String getSmallestAndLargest(String s, int k) {
String smallest = s.substring(0,k);
String largest = s.substring(0,k);
String s1 = "";
int i;
int l = s.length();
for(i=0;i<=l-k;i++){
s1=s.substring(i,k+i);
if(smallest.compareTo(s1)>0)
smallest=s1;
if(largest.compareTo(s1)<0)
largest=s1;
s1="";
}
return smallest + "\n" + largest;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String s = scan.next();
int k = scan.nextInt();
scan.close();
System.out.println(getSmallestAndLargest(s, k));
}
}