String
// String functions
import java.util.*;
class StrHandling
{
public static void main(String as[])
{
String s[] = new String[10];
Scanner sc = new Scanner(System.in);
System.out.print("Enter Number of Strings : ");
int N = Integer.parseInt(sc.nextLine());
System.out.println("Enter Strings : ");
for(int i = 0; i < N; i++)
s[i] = sc.nextLine();
//Sort
for(int i=0;i<N-1;i++)
{
for(int j=i+1;j<N;j++)
{
if((s[i].compareTo(s[j]))>0)
{
String tmp = s[i];
s[i] = s[j];
s[j] = tmp;
}
}
}
System.out.println("Sorted Strings : ");
for(int i = 0;i<N;i++)
System.out.println(s[i]);
}
}
No comments:
Post a Comment
Don't be a silent reader...
Leave your comments...
Anu