Skip to content

Commit 6432a32

Browse files
authored
Update reverse.cs
1 parent 0cddd7e commit 6432a32

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Algorithms/Strings/reverse.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
using System;
2+
using System.Text;
23

34
namespace Algorithms.Strings;
45

56
public static class ReversedString
67
{
78
//comment
8-
// In this Main Method we are taking the input and calling ReverseString Method which will return reversedString and we will print in main Method
9+
//In this Main Method we are taking the input and calling ReverseString Method which will return reversedString and we will print in main Method
910
//comment
1011
public static void Main(string[] args)
1112
{
1213
// Sample Input : "reverse"
1314
// Sample Output : "esrever"
1415
string input= Console.ReadLine();
15-
string reversedString = ReverseString(input.Trim());
16-
Console.WriteLine(reversedString);
16+
ReverseString(input.Trim());
1717
}
1818

1919
//comment
20-
// This Method will take input as string and return the reversed string
20+
//This Method will take input as string and return the reversed string
2121
//comment
2222

23-
public static string ReverseString (string input)
23+
public static void ReverseString (string input)
2424
{
25-
string reverseString="";
25+
StringBuilder reverseString= new StringBuilder();
2626
int length = input.Length;
2727
while(length!=0)
2828
{
29-
reverseString= reverseString+input[length-1];
29+
reverseString.Append(input[length-1]);
3030
length-=1;
3131
}
32-
return reverseString;
32+
Console.WriteLine(reverseString);
3333
}
3434
}

0 commit comments

Comments
 (0)