Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Read a string and reverse it and then print in alphabetical order.

                         

A string is a contiguous sequence of symbols or values, such as a character string (a sequence of characters) or a binary digit string (a sequence of binary values). In the example given below takes string value from user and reverse that string by using String reverse(String str) method and set in alphabetical order by String alphaOrder(String str) method. Note that passed string by user must be in upper case or in lower case but mixed cases are not permitted for this example.

Program asks the user to enter the input string. Once it is entered by the user, the program performs the reverse operations.

Program: Read a string reverse it and arrange in alphabetical order.

ReverseAlphabetical.java

      /**
      * read a string and reverse it and then write in alphabetical order.
     */
     import java.io.*;
     import java.util.*;

     class ReverseAlphabetical {
 
           String reverse(String str) {
               String rStr = new StringBuffer(str).reverse().toString();
               return rStr;
           }


           String alphaOrder(String str){
               char[] charArray = str.toCharArray();
               Arrays.sort(charArray);
               String aString = new String(charArray);
                return aString ;
           }

           public static void main(String[] args) throws IOException {
              System.out.print("Enter the String : ");
             BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
              String inputString = br.readLine();
              System.out.println("String before reverse : " + inputString);
              ReverseAlphabetical obj = new ReverseAlphabetical();
              String reverseString = obj.reverse(inputString);
              String alphaString = obj.alphaOrder(inputString);
              System.out.println("String after reverse : " + reverseString);
              System.out.println("String in alphabetical order : " + alphaString);
           }
      }

Output of the program:

Enter the String : mahendra
String before reverse : mahendra
String after reverse : ardneham
String in alphabetical order : aadehmnr

Download source code

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Latest Searches:
concatenate java
clear the console in j
for loop
download struts applic
create file folder
jasper report
java display applet me
servlet exception hand
Icon
code for how connect j
struts-config
java program examples
jsp to jdbc codes
<SELECT> and Post
ล ยà¸?ฤ??????à¸
getter setter methods
c:out in var of c:fore
upload file using ajax
placeholder
Flex TreeGrid
Photoshop Drawing Penc
Quartz
Java / multi thread
ASP Ad Management Crea
insert data to text fi
example
create a tree to be di
WHERE Statement in SQL
factory method
username and password
Photoshop Animation An
java jtable
permutation
JDBC with Mysql in Ecl
multiple submit button
Button
data ware
oracle.jdbc.driver.Dat
server side validation
draw Polyline
web.xml file
convert string to stin
breakั?�??????ั?
org.gjt.mm.mysql.Drive
compare java.util.date
struts formfile
JavaWorld article abou
Photoshop Basics Using
logout session
system.out.println(x
data binding
program to find greate
project in session bea
ant script web and ejb
select from statment
writing data to file
panelgrid colspan
jdbc connections
intranet applications
Exercise - Pad Left
example for org.jfree.
Delete database
XML Class Constructor
Passing Parameters in
Display detailed cloc
Reading Nested dom ele
swt
page refresh
Add a file finder
Refresh a Web Page Usi
Build scripts with Gro
DOM
hibernate findall
insert fields blob
count row in resultset
token string
java programs usin pus
mysql blob
Insert an array list o
javabean program
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.