-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
44 lines (39 loc) · 1.07 KB
/
Program.cs
File metadata and controls
44 lines (39 loc) · 1.07 KB
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
44
// Сформировать массив со строками, длина которых не более трех символов
// на основе заданного массива
void PrintArray(string[] array)
{
Console.Write("[");
for (int i = 0; i < array.Length; i++)
{
if (i < array.Length - 1) Console.Write($"{array[i]}, ");
else Console.Write($"{array[i]}");
}
Console.WriteLine("]");
}
string[] setArray(string[] array)
{
int len = 0;
for (int i = 0; i < array.Length; i++)
{
if (array[i].Length <= 3)
{
len++;
}
}
int index = 0;
string[] newArray = new string[len];
for (int i = 0; i < array.Length; i++)
{
if (array[i].Length <= 3)
{
newArray[index] = array[i];
index++;
}
}
return newArray;
}
//string[] arrayStr = { "hello", "2", "world", ":-)" };
string[] arrayStr = { "1234", "1657", "-2", "computer science" };
PrintArray(arrayStr);
string[] newArrayStr = setArray(arrayStr);
PrintArray(newArrayStr);