-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLexicographical_Order.java
More file actions
38 lines (38 loc) · 1.02 KB
/
Lexicographical_Order.java
File metadata and controls
38 lines (38 loc) · 1.02 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
import java.io.*;
public class Lexicographical_Order
{
public static void main(String args[])throws IOException
{
String s,s2;
int l,i=0,j,k=0,p=0,c=0;
System.out.println("\tThe Lexicographical Order Program\n");
System.out.println("Enter The String:");
BufferedReader as=new BufferedReader(new InputStreamReader(System.in));
s=as.readLine();
s=s+' ';
l=s.length();
String s1[]=new String[l];
for(;i<l;i++)
{
if(s.charAt(i)== ' ')
{
s1[c]=s.substring(p,i);
p=i+1;
c++;
}
}
for(i=0;i<c;i++)
{
k=i;
for(j=i+1;j<c;j++)
if(s1[k].compareTo(s1[j])>0)
k=j;
s2=s1[k];
s1[k]=s1[i];
s1[i]=s2;
}
System.out.println("Lexicographical Order:");
for(i=0;i<c;i++)
System.out.print(s1[i]+" ");
}
}