Arrange Alphabets - Descending Order JAVA EASY-PART005
Arrange Alphabets - Descending Order
A string S (with only LOWER case alphabets and length from 3 to 100) will be passed as input. The program should print the alphabets in the string in descending order.
***********************************************************************************
import java.util.*;
public class Hello {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
char c[]=s.toCharArray();
Arrays.sort(c);
String n=new String(c);
StringBuilder h=new StringBuilder("");
for(char str:c)
{String k=h.toString();
String u=new String(str+"");
if(!(k.contains(u)))
h.append(str);
}
for(int i=h.length()-1;i>=0;i--)
System.out.print(h.charAt(i));
}
}
***********************************************************************************
Comments
Post a Comment