I am trying to find the number of duplicate characters in an array and list them. For example, the user enters "this is my house", the output should look like this:
Number of duplicate characters is: 3 and the duplicates are: h i s
I have to use ToCharArray()
I've been trying but I can't get it to work properly, can you please help?
Thanks
Here is my code:
using System;
class Program
{
static void Main()
{
Console.Write("type a sentence: ");
String str = Console.ReadLine();
char[] arr = str.ToCharArray();
for (int j = 0; j < arr.Length; j++)
{
for (int k = j + 1; k < arr.Length; k++)
{
if (arr[j] == arr[k] && j != k)
{
Console.WriteLine("number of duplicates: " + k + "\n" + "duplicates are: " + arr[j]);
Console.ReadLine();
}
}
}
}
}