- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJavaSubstringCompare.java
More file actions
Latest commit
31 lines (23 loc) · 850 Bytes
/
Copy pathJavaSubstringCompare.java
File metadata and controls
31 lines (23 loc) · 850 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
packageStrings;
importjava.util.Scanner;
publicclassJavaSubstringCompare {
publicstaticStringgetSmallestAndLargest(Strings, intk) {
Stringsmallest = "";
Stringlargest = "";
java.util.List<String> substrings = newjava.util.ArrayList<String>();
for (intx = 0, l = s.length() - (k - 1); x < l; x++) {
substrings.add(s.substring(x, x + k));
}
java.util.Collections.sort(substrings);
smallest = substrings.get(0);
largest = substrings.get(substrings.size() - 1);
returnsmallest + "\n" + largest;
}
publicstaticvoidmain(String[] args) {
Scannerscan = newScanner(System.in);
Strings = scan.next();
intk = scan.nextInt();
scan.close();
System.out.println(getSmallestAndLargest(s, k));
}
}