@@ -0,0 +1,1718 @@
+package java_problems.strings;%0D%0A%0D%0Aimport java.util.*;%0D%0A%0D%0A/*%0D%0A * Today we will learn about java strings. Your task is simple, given a string,%0D%0A * find out the lexicographically smallest and largest substring of length k.%0D%0A * %0D%0A * %5BNote: Lexicographic order is also known as alphabetic order dictionary%0D%0A * order. So %22ball%22 is smaller than %22cat%22, %22dog%22 is smaller than %22dorm%22. %0D%0A * Capital letter always comes before smaller letter, so %22Happy%22 is smaller%0D%0A * than %22happy%22 and %22Zoo%22 is smaller than %22ball%22.%5D%0D%0A * %0D%0A * Input Format%0D%0A * %0D%0A * First line will consist a string containing english alphabets which has at%0D%0A * most 1000 characters. 2nd line will consist an integer k.%0D%0A * %0D%0A * Output Format%0D%0A * %0D%0A * In the first line print the lexicographically minimum substring. In the%0D%0A * second line print the lexicographically maximum substring.%0D%0A * %0D%0A * Sample Input:%0D%0A * %0D%0A * welcometojava%0D%0A * 3%0D%0A */%0D%0Apublic class JavaStrings %7B%0D%0A%0D%0A%09public static void main(String%5B%5D args) %7B%0D%0A        Scanner sc = new Scanner(System.in);%0D%0A        System.out.println(%22Enter a string: %22);%0D%0A        String test = sc.nextLine();%0D%0A        System.out.println(%22Enter an integer: %22);%0D%0A        int subLength = sc.nextInt();%0D%0A        String min = test.substring(0, subLength);%0D%0A        String max = test.substring(0, subLength);%0D%0A        String sub = %22%22;%0D%0A        for (int i = 1; i %3C test.length() - (subLength - 1); i++) %7B%0D%0A            sub = test.substring(i, i + subLength);%0D%0A            if (min.compareTo(sub) %3E 0) %7B%0D%0A                min = sub;%0D%0A            %7D else if (max.compareTo(sub) %3C 0) %7B%0D%0A                max = sub;%0D%0A            %7D%0D%0A        %7D%0D%0A        sc.close();%0D%0A        System.out.println(min);%0D%0A        System.out.println(max);%0D%0A    %7D%0D%0A%7D

Add JavaStrings