Arranging String in alphabetical order.

Write a program to input a string. Convert into uppercase. Print the string also print the same string after arranging each letter in alphabetical order. E.g. INPUT: COBOL   OUTPUT: BCLOO




SOURCE CODE




import java.io.*;
import java.util.*;
public class arranging_string
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        System.out.print("\nEnter a String :");
        String str1=sc.nextLine();
        String str=str1.toUpperCase();
        System.out.println("Entered string  = "+str1);
        System.out.println("Converted string= "+str);
        System.out.print("Reverse string    = ");
        for(char ch='A';ch<='Z';ch++)
        {
            for(int i=0;i<str.length();i++)
            {
                if(ch==str.charAt(i))
                {
                    System.out.print(str.charAt(i));
                }
            }
        }
    }
}



OUTPUT




If you have any question then leave a comment below I will do my best to answer that question.

Comments

Popular posts from this blog

[Question 3] ISC 2017 Computer Practical Paper Solved – Caesar Cipher.

Pattern of your own name.

Designing Patterns - Print 'Z'.