import java.io.*;
import java.util.*;
import java.lang.*;
class sort
{
public static void main(String[] args) throws IOException
{
char c[]=new char[20];
char d[]=new char[20];
System.out.println("Enter a string");
DataInputStream in=new DataInputStream(System.in);
String str;
str=(in.readLine()).toLowerCase();
for(int i=0;i<str.length();i++)
{
c[i]=str.charAt(i);
}
char temp;
for(int i=0;i<str.length();i++)
{
for(int j=i+1;j<str.length();j++)
{
if(c[i]>c[j])
{
temp=c[i];
c[i]=c[j];
c[j]=temp;
}
}
}
System.out.println("String after sorting alphabetically:");
for(int i=0;i<str.length();i++)
System.out.print(c[i]);
}
}
import java.util.*;
import java.lang.*;
class sort
{
public static void main(String[] args) throws IOException
{
char c[]=new char[20];
char d[]=new char[20];
System.out.println("Enter a string");
DataInputStream in=new DataInputStream(System.in);
String str;
str=(in.readLine()).toLowerCase();
for(int i=0;i<str.length();i++)
{
c[i]=str.charAt(i);
}
char temp;
for(int i=0;i<str.length();i++)
{
for(int j=i+1;j<str.length();j++)
{
if(c[i]>c[j])
{
temp=c[i];
c[i]=c[j];
c[j]=temp;
}
}
}
System.out.println("String after sorting alphabetically:");
for(int i=0;i<str.length();i++)
System.out.print(c[i]);
}
}
No comments :
Post a Comment