I need to create a recursion that will count in array the letter 'x'.
I solved it, but it don't know if this is what they meant that i would do.
I have just started to learn this subject.
If it's not a recursion or it's not a good way to solve my problem i will glad if you will help me to fix it.
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] str = StringArray();
}
public static string[] StringArray()
{
Console.WriteLine("Array Size:");
int size = int.Parse(Console.ReadLine());
string[] a = new string[size];
string result = "";
Console.WriteLine("Array Values:");
for (int i = 0; i < a.Length; i++)
{
a[i] = Console.ReadLine();
result += a[i];
}
int sum = 0;
for (int i = 0; i < result.Length; i++)
{
if (result[i] == 'x')
{
sum++;
}
}
Console.WriteLine(sum);
return a;
}
}
}