Home Java Beginners Reverse String



Reverse String
Posted on: December 18, 2008 at 12:00 AM
In this example we are demonstrating the command line argument and displaying it in its backward direction on the console.

Reverse String

     

In this example we are demonstrating the command line argument and displaying it in its backward direction on the console.

Description of program:

In the example given below, we are taking a command line argument and storing it in a string type array passed into the main method. Then we are taking a loop backward through the array of arguments and one more loop backwards through the characters in each argument and then printing out character j of argument i, adding the space at the end of each argument and at the end terminating the line when we're done.

public class ReverseString {
  
  public static void main(String[] args) {  
  for(int i = args.length-1; i >= 0; i--) {
  for(int j=args[i].length()-1; j>=0; j--) {
  System.out.print(args[i].charAt(j));
  }
  System.out.print(" ");
  }
  System.out.println();
  }
}


Here is the output:

C:\Examples>java Reverse roseindia 
aidniesor


Download of this program.

 

Related Tags for Reverse String:
ccomconsoleiodisplaycommandolelinethiswarexampleexamargumenteratingitbackcommademolisplmaninmntplaytrispdirectionemdirmeackxaxampsrectspsodisplayingdirectatplayingkisirmplandarconsstrssrdthstatidispisplayingpleplndonomolo


More Tutorials from this section

Ask Questions?    Discuss: Reverse String  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.