-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
43 lines (33 loc) · 1.18 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Linq;
namespace ReverseArrayofStrings
{
class Program
{
static void Main(string[] args)
{
////Read an array of strings (space separated values), reverse it and print its elements
string[] arr = Console.ReadLine()
.Split(" ", StringSplitOptions.RemoveEmptyEntries)
.ToArray();
for (int i = 0; i < arr.Length/2; i++)
{
string oldElement = arr[i];
arr[i] = arr[arr.Length - 1 - i];
arr[arr.Length - 1 - i] = oldElement;
}
Console.WriteLine(string.Join(" ",arr));
//option 2
//string[] arrayOfStrings = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Reverse().ToArray();
//foreach (var item in arrayOfStrings)
//{
// Console.Write($"{item} ");
//}
//option 3
//string[] arr = Console.ReadLine()
// .Split(" ",StringSplitOptions.RemoveEmptyEntries)
// .ToArray();
//Console.WriteLine(string.Join(' ',arr.Reverse()));
}
}
}