Program in Java For sorting the string in string in alphebetical order - Code

Latest

programs

Monday, October 10, 2011

Program in Java For sorting the string in string in alphebetical order


Program in Java For sorting the string in string in alphebetical order


import java.lang.*;
import java.io.*;
class asc
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("enter how many strings");
int n=Integer.parseInt(br.readLine());
String x[]=new String[n];
System.out.println("enter "+n+" strings");
for(int i=0;i<n;i++)
{
x[i]=br.readLine();
}
String s=new String();
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(x[i].compareTo(x[j])<0)
{
s=x[i];
x[i]=x[j];
x[j]=s;
}
}
}
System.out.println("string in alphebetical order are");
for(int i=0;i<n;i++)
{
System.out.println(x[i]);

}
  
}
}

No comments:

Post a Comment