You are viewing a single comment's thread. Return to all comments →
public static String getSmallestAndLargest(String s, int k) { String smallest = s.substring(0, k); String largest = s.substring(0, k); for (int i = 1; i <= s.length() - k; i++) { String substring = s.substring(i, i + k); if (substring.compareTo(smallest) < 0) { smallest = substring; } if (substring.compareTo(largest) > 0) { largest = substring; } } return smallest + "\n" + largest; }
Seems like cookies are disabled on this browser, please enable them to open this website
Java Substring Comparisons
You are viewing a single comment's thread. Return to all comments →