Sort N Strings - Descending OrderN strings are passed as input. The program must sort them in the descending order.
Input Format:
The first line contains the value of N. Next N lines contain the value of N string values.
Output Format:
N lines containing the N string values sorted in descending order.
Boundary Conditions:
2 <= N <= 15
Length of a string is between 2 and 100.
Example Input/Output 1:
Input:
6
Apple
banana
Boy
Zoo
Hat
heckle
Output:
heckle
banana
Zoo
Hat
Boy
Apple
Code:
import java.util.*;
public class Hello {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String[] str=new String[n];
int i;
for(i=0;i<n;i++)
str[i]=sc.next();
Arrays.sort(str);
for(i=str.length-1;i>=0;i--)
System.out.println(str[i]);
}
}
No comments:
Post a Comment