Reverse String in c#
class ReversString
{
static string reversText(string text)
{
StringBuilder sb = new StringBuilder();
for (int i = text.Length-1; i >= 0; i--)
{
sb.Append(text[i]);
}
return sb.ToString();
}
static void Main()
{
Console.WriteLine("Enter the string");
string str = Console.ReadLine();
string reversed = reversText(str);
Console.WriteLine(reversed);
Console.ReadLine();
}
}
Output:
class ReversString
{
static string reversText(string text)
{
StringBuilder sb = new StringBuilder();
for (int i = text.Length-1; i >= 0; i--)
{
sb.Append(text[i]);
}
return sb.ToString();
}
static void Main()
{
Console.WriteLine("Enter the string");
string str = Console.ReadLine();
string reversed = reversText(str);
Console.WriteLine(reversed);
Console.ReadLine();
}
}
Output:
No comments:
Post a Comment