Repository navigation
Expand file tree
/
Copy pathSub_String.java
More file actions
71 lines (59 loc) · 1.76 KB
/
Copy pathSub_String.java
File metadata and controls
71 lines (59 loc) · 1.76 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.util.Scanner;
public class Sub_String
{
public static String getSmallestAndLargest(String s, int k)
{
String smallest = "";
String largest = "";
s=s.trim();
int l=s.length();
int count=0;
String St[]=new String[(l-k+1)];
int len=St.length;
for(int i=0;(i+k)<=l;i++)
{
St[count++]=s.substring(i,i+k);
}
for(int i=0;i<St.length-1;i++)
{
String check=St[i];
check=check.toLowerCase();
for(int j=i+1;j<St.length;j++)
{
String check2=St[j];
check2=check2.toLowerCase();
for(int m=0;m<k;m++)
{
if(check.charAt(m)==check2.charAt(m))
{
continue;
}
else
{
if(check.charAt(m)>check2.charAt(m))
{
String swap=St[i];
St[i]=St[j];
St[j]=swap;
check=St[i];
check2=St[j];
break;
}
else
break;
}
}
}
}
smallest=St[0];
largest=St[len-1];
return smallest + "\n" + largest;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String s = scan.next();
int k = scan.nextInt();
scan.close();
System.out.println(getSmallestAndLargest(s, k));
}
}