Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 26-11-2009
Member
 
Join Date: Jan 2009
Posts: 721
program to reverse a string in java.

Hi,
I am new to programming language. I recently started learning java language. Yesterday our sir has given us program like write program to reverse a string in java. I use various method but I unable to write that program. That's why I asked this question on this forum. So if you have any idea about this please help me.Thanks in advanced.
Reply With Quote
  #2  
Old 26-11-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: program to reverse a string in java.

This is the simple program I had ever made. Just try to understand each steps carefully.




Code:
public class ReverseST
          {
          public static void main(String[] args) 
              {
                 String Word = "Welcome to this problem";
             System.out.println(ReverseString.reverseIt(Word));
               }
         }

         class ReverseS
          {
            public static String reverseIt(String source) 
            {
           int p, pen = source.length();
    StringBuffer dest = new StringBuffer(pen);

    for (p = (pen - 1); p >= 0; p--)
      dest.append(source.charAt(p));
    return dest.toString();
  }
}
Reply With Quote
  #3  
Old 26-11-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: program to reverse a string in java.

In this program I used array.Just go through it.



Code:
public class ReverseString
    {
    public static void main(String[] args)
    {
    String str=args[0];
    String rev = new StringBuffer(str).
reverse().toString();
    System.out.println("\nString before reverse the word:"+str);
    System.out.println("String after reverse the word:"+rev);
  }     
}
Reply With Quote
  #4  
Old 26-11-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: program to reverse a string in java.

You can used reverse function injava to reverse the program.


Code:
  public class StringReverse
  {

   public static void main(String args[])
  {

  String strOgi = "Hello World";

  System.out.println(" String before reverse : " + strOgi);
  strOgi = new StringBuffer(strOgi).reverse().toString();


  System.out.println(" String after reverse : " + strOgi);

  }

  }
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "program to reverse a string in java."
Thread Thread Starter Forum Replies Last Post
Java program to iterate a subset of a string. Nadiaa Software Development 5 19-03-2012 01:53 PM
How to compare string using java program regardless of their case? MAGALY Software Development 4 30-01-2010 07:23 PM
Java program to reverse the order of LinkedList elements? MKAIF Software Development 5 22-01-2010 09:44 PM
How to write string data to file using java program? Linoo Software Development 5 21-01-2010 09:26 PM


All times are GMT +5.5. The time now is 02:54 AM.