Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- class sort
- {
- public static void main(String args[])
- {
- Scanner t = new Scanner(System.in);
- System.out.println("enter total no. of strings");
- int n = t.nextInt();
- String s[] = new String[n];
- int i,j,k,l;
- System.out.println("enter strings");
- for(i=0;i<n;i++)
- {
- s[i]=t.next();
- }
- String temp = new String();
- for(i=0;i<=n-2;i++)
- {
- for(j=0;j<=n-2;j++)
- {
- if(s[j].compareTo(s[j+1])>0)
- {
- temp = s[j];
- s[j] = s[j+1];
- s[j+1] = temp;
- }
- }
- }
- System.out.println("sorted strings are given below:");
- for(i=0;i<n;i++)
- {
- System.out.println(s[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement