-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaStringCompare.java
More file actions
30 lines (26 loc) · 1.06 KB
/
JavaStringCompare.java
File metadata and controls
30 lines (26 loc) · 1.06 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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class JavaStringCompare {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
String str = sc.next();
int len = sc.nextInt();
String[] str_arr = new String[str.length()-len+1];
for(int i=0; i<=str.length()-len; i++) {
str_arr[i] = (str.substring(i,i+len));
}
/* Lexicographically sort an array of strings. */
Arrays.sort(str_arr);
/*
Lexicographically sort an array of strings in a reverse order.
Arrays.sort(str_arr, Collections.reverseOrder());
*/
// System.out.println(Arrays.toString(str_arr));
System.out.println("Lexicographically minimun substring: "+ str_arr[0]);
System.out.println("Lexicographically maximum substring: "+ str_arr[str.length()-len]);
}
}