Alphabetical order of the given Name
Program Name:- alpha.java
import java.io.*;
import java.lang.*;
class alpha
{
public static void main(String args[])throws IOException
{
String a[]=new String[10];
String b;
int n;
DataInputStream in=new DataInputStream(System.in);
System.out.print("\nEnter the Number of name :");
n=Integer.parseInt(in.readLine());
for(int i=0;i<n;i++)
{
a[i]=in.readLine();
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(a[i].compareTo(a[j])<0)
{
b=a[i];
a[i]=a[j];
a[j]=b;
}
}
}
System.out.println("\n Alphabetical order of name is:");
for(int i=0;i<n;i++)
{
System.out.println(a[i]);
}
}
}
No comments:
Post a Comment