import java.io.*;
class charsort
{ public static void main(String args[])throws IOException
{ String s1;
char temp;
DataInputStream in=new DataInputStream(System.in);
System.out.print("\n\n Enter string: ");
s1=in.readLine();
char z[]=new char[s1.length()];
z[0]+=s1.charAt(0);
for(int i=1;i<s1.length();i++)
{ z[i]+=s1.charAt(i);
for(int j=0;j<=i;j++)
{ for(int k=j+1;k<=i;k++)
{ if(z[j]>z[k])
{ temp=z[k];
z[k]=z[j];
z[j]=temp;
}
}
}
}
System.out.print("\n\n Sorted string is: ");
for(int m=0;m<s1.length();m++)
System.out.print(z[m]);
}
}
Comments
Post a Comment