using System;
namespace Console_ReverseString
{
class ReverseString
{
//Using While Loop
public void dispRevStr()
{
string Str, Revstr = "";
int Length;
Console.Write("Enter A String : ");
Str = Console.ReadLine();
Length = Str.Length - 1;
while (Length >= 0)
{
Revstr = Revstr + Str[Length];
Length--;
}
Console.WriteLine("Reverse String Is {0}", Revstr);
}
//Using For loop
//public void dispRevStr()
//{
// string Str, Revstr = "";
// Console.Write("Enter A String : ");
// Str = Console.ReadLine();
// for (int i = Str.Length - 1; i >= 0; i--)
// {
// Revstr = Revstr + Str[i];
// }
// Console.WriteLine("Reverse String Is {0}", Revstr);
// Console.ReadLine();
//}
static void Main(string[] args)
{
ReverseString rs = new ReverseString();
rs.dispRevStr();
Console.ReadKey();
}
}
}
No comments:
Post a Comment