Repository navigation
Expand file tree
/
Copy pathSortedWord.java
More file actions
85 lines (79 loc) · 1.41 KB
/
Copy pathSortedWord.java
File metadata and controls
85 lines (79 loc) · 1.41 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class SortedWord
{
/*static void SortedWord(String s)
{
int i=0,j=0,k=0;
char temp[]=new char[s.length()];
temp[0]=s.charAt(0);
for(j=1,i=1;i<s.length();i++)
{
if(s.charAt(i)==' ')
{
temp[j]=s.charAt(i+1);
j++;
}
}
SortedOrder(temp);
System.out.println(temp);
for(i=0;i<temp.length;i++)
{
for(k=1;k<s.length();k++)
{
if((temp[i]==s.charAt(k))&&(s.charAt(k-1)==' '))
{
for(j=i;s.charAt(j)!=' ';j++)
{
if(j==s.length()-1)break;
System.out.print(s.charAt(j));
}
System.out.println("");
break;
}
}
}
}
static void SortedOrder(char[] s)
{
int i=0,j=0;char t;
char temp[]=new char[s.length];
temp=s;
for(i=0;i<temp.length-1;i++)
{
for(j=i+1;j<temp.length;j++)
{
if((int)temp[i]>(int)temp[j])
{
t=temp[i];
temp[i]=temp[j];
temp[j]=t;
}
}
}
}*/
static void SortedWord(String s)
{
int i=0,j=0,k=0;
char temp[]=new char[s.length()];
for(i=0;s.charAt(i)!=' ';i++)
{
temp[i]=s.charAt(i);
}
for(i=1;i<s.length();i++)
{
if((int)temp[0]<(int)s.charAt(i)&&s.charAt(i-1)==' ')
{
for(j=i,k=0;s.charAt(j)!=' ';j++,k++)
{
if(j==s.length()-1) break;
temp[k]=s.charAt(j);
}
}
}
}
public static void main(String... args)
{
String str=new String("shivam gagan bhumika amit");
System.out.println(str+"\nSorted Order:");
SortedWord(str);
}
}