// AIM : Write a Java Program to read 5 strings and sort the strings in ascending order
import java.io.*;
class strsort
{
public static void main(String arg[]) throws IOException
{
int i,j,len;
String s[]=new String[5],swp;
DataInputStream in=new DataInputStream(System.in);
System.out.println("Enter 5 strings ?");
for(i=0;i<=4;i++)
s[i]=in.readLine();
for(i=0;i<=3;i++)
{
for(j=i+1;j<=4;j++)
if(s[i].compareTo(s[j])>0)
{
swp=s[i];
s[i]=s[j];
s[j]=swp;
}
}
System.out.println("After sort....");
for(i=0;i<=4;i++)
System.out.println(s[i]);
}
}
No comments:
Post a Comment