You are viewing a single comment's thread. Return to all comments →
public static String getSmallestAndLargest(String s, int k) { String smallest = ""; String largest = "";
smallest = s.substring(0,k); largest = s.substring(0,k); int star = 0; while(k < s.length()+1){ String cons = s.substring(star, k); if(cons.compareTo(largest) > 0){ largest = cons; } if(cons.compareTo(smallest) < 0){ smallest = cons; } star++; k++; } 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 →
public static String getSmallestAndLargest(String s, int k) { String smallest = ""; String largest = "";