File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change 1
1
using System ;
2
+ using System . Text ;
2
3
3
4
namespace Algorithms . Strings ;
4
5
5
6
public static class ReversedString
6
7
{
7
8
//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
9
10
//comment
10
11
public static void Main ( string [ ] args )
11
12
{
12
13
// Sample Input : "reverse"
13
14
// Sample Output : "esrever"
14
15
string input = Console . ReadLine ( ) ;
15
- string reversedString = ReverseString ( input . Trim ( ) ) ;
16
- Console . WriteLine ( reversedString ) ;
16
+ ReverseString ( input . Trim ( ) ) ;
17
17
}
18
18
19
19
//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
21
21
//comment
22
22
23
- public static string ReverseString ( string input )
23
+ public static void ReverseString ( string input )
24
24
{
25
- string reverseString = "" ;
25
+ StringBuilder reverseString = new StringBuilder ( ) ;
26
26
int length = input . Length ;
27
27
while ( length != 0 )
28
28
{
29
- reverseString = reverseString + input [ length - 1 ] ;
29
+ reverseString . Append ( input [ length - 1 ] ) ;
30
30
length -= 1 ;
31
31
}
32
- return reverseString ;
32
+ Console . WriteLine ( reverseString ) ;
33
33
}
34
34
}
You can’t perform that action at this time.
0 commit comments