You are on page 1of 1

package SLS_Assignment_XI_Anual;

import java.util.*;
public class Alphabetical_Sort
{
String s; String x[];
void Accept()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter sentence : ");
s = sc.nextLine();
}
void Show()
{
x = (s + " ").split(" ");
System.out.println("After sorting : ");
for(String i : x)
System.out.print(Sort(i) + " ");
}
String Sort(String x)
{
char temp = ' '; char c[] = x.toCharArray();
for(int i = 0 ; i < c.length - 1 ; i++)
{
for(int j = 0 ; j < c.length - 1 - i ; j++)
if(c[j] > c[j+1])
{
temp = c[j]; c[j] = c[j+1]; c[j+1] = temp;
}
}
return String.valueOf(c);
}
public static void main(String args[])
{
Alphabetical_Sort obj = new Alphabetical_Sort();
obj.Accept(); obj.Show();
}
}

You might also like