-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlphabetic_Arrange.java
More file actions
46 lines (46 loc) · 1.08 KB
/
Copy pathAlphabetic_Arrange.java
File metadata and controls
46 lines (46 loc) · 1.08 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
import java.util.Scanner;
class Alphabetic_Arrange
{
public static void main(String args[])
{
String s,r="",temp="";
int c=0,k=0;
Scanner sc=new Scanner(System.in);
System.out.println("enter the sentence");
s=sc.nextLine();
s=s+' ';
int l=s.length();
for(int j=0;j<l;j++)
{
if(s.charAt(j)==' ')
c++;
}
String a[]=new String[c];
for(int i=0;i<l;i++)
{
if(s.charAt(i)!=' ')
r=r+s.charAt(i);
else
{
a[k++]=r;
r="";
}
}
for(int j=0;j<c-1;j++)
{
for(int i=j+1;i<c;i++)
{
if(a[j].charAt(0)>a[i].charAt(0))
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
System.out.println("The sorted string is");
for(int j=0;j<c;j++)
System.out.print(a[j]+" ");
System.out.print(".");
}
}