How to reverse a string through programming( In C, C#, JAVA)

If you want to reverse a string , just take a string variable and a character array and the length of the array must be same as the length of string , You can achieve this by finding the length of string. And then store the string into character array.
Now to display the string in reverse manner, Just print the array from last index to first index!!!
The example is shown here, it is in C#, you can change it into any of language by just changing the syntax.






using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            string _myString;
            Console.WriteLine("Enter any string ");
            _myString = Console.ReadLine();
            int _length = _myString.Length;
            char[] _reverse = new char[_length];
            for (int i = 0; i < _length; i++)
            {
                _reverse[i] = _myString[i];
            }
            for (int i = _length-1; i >= 0; i--)
            {
                Console.Write(_reverse[i]);
            }
            Console.ReadLine();
        }
    }
}

6 comments:

  1. Just desire to say your write-up is impressive.
    The clearness within your publish is simply impressive and
    i can get for granted you happen to be an expert on this field.
    Well together with your permission let me to grab
    your rss feed to help keep as much as date with future posts.

    Many thanks a million and remember to maintain up the solid
    function.

    Also visit my blog post: 2gts dvds

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Eclipse is hands down my biggest time saver. I don't know how I coded before auto-complete and continuous compilation. There are some drudgery tasks in coding that IDEs like Eclipse can make short work of. Example: You are writing a class which implements an interface. You can use the New Class wizard to specify the class name and the interface class. Eclipse generates the class code with method stubs for the interface implementation. There are other features like generating constructors, generating getters and setters, and generating delegate methods. Set aside some development time to explore the IDE a little and become familiar with its features.

    java training in chennai

    ReplyDelete
  5. Interesting post! This is really helpful for me. I like it! Thanks for sharing!
    Mobile application developers in Chennai | PHP developers Chennai

    ReplyDelete

Powered by Blogger.