×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Write a program in java to display the following pattern. Write a programme in java to accept a month name and print the month number.
Write a programme to accept a word and display the alphabets in an alphabetical order. - Java
6128    Arnab De    11/06/2018

Write a programme to accept a word and display the alphabets in an alphabetical order.

First of all we convert the string into lower case. Now as we know, String is not a mutable, we convert the string into a StringBuffer Object. Now easily use the selection sort method on the StringBuffer object. Here we use a method setCharAt(), which is in the StringBuffer class but not in String Class.

softetechnologies
import java.util.*;
public class AlphaSort
{
    public static void main(String []args)
    {
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter A String : ");
        String str=sc.nextLine();
        str=str.toLowerCase();
        StringBuffer sb=new StringBuffer(str);
        char c;
        for(int i=0;i<sb.length();i++)
        {
            for(int j=0;j<sb.length();j++)
            {
                if(sb.charAt(i)<sb.charAt(j))
                {
                    c=sb.charAt(i);
                    sb.setCharAt(i,sb.charAt(j));
                    sb.setCharAt(j,c);
                }
            }
        }
        System.out.println(sb.toString().trim());
    }
}
softetechnologies

Output

Enter A String : national Public school
aabcchiillnnooopstul

Write a program in java to display the following pattern. Write a programme in java to accept a month name and print the month number.
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Sri Sri Ramakrishna Paramahamsa
One cannot be spiritual as long as one has shame, hatred, or fear.
Sri Sri Ramakrishna Paramahamsa
16223
52.48
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     41979
01/01/2018     35991
28/06/2017     34082
25/06/2018     33432
02/08/2017     32394
01/08/2017     26807
06/07/2017     26785
15/05/2017     26415
14/07/2017     21851
21/04/2018     20711
softetechnologies