We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Solution in java 15. I had to import ArrayList and Comparator classes.
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String s = scan.next();
int k = scan.nextInt();
ArrayList<String> lista = new ArrayList<String>();
for (int i= 0; i < s.length()-(k-1);i++){
lista.add(s.substring(i,k+i));
}
lista.sort(Comparator.naturalOrder());
System.out.println(lista.get(0));
System.out.println(lista.get(lista.size()-1));
}
Java Substring Comparisons
You are viewing a single comment's thread. Return to all comments →
Solution in java 15. I had to import ArrayList and Comparator classes.
}