First repeated character

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FirstNonRepeatingCharacter
{
class Program
{
static void Main(string[] args)
{

bool[] arr = new bool[256];
bool repeated = false;

Console.WriteLine("Enter the string" );
string str = Console.ReadLine();

if (str.Equals(""))
{
Console.WriteLine("String is null");
Console.ReadLine();
return;
}

foreach (char ch in str)
{
if (!arr[(int)ch] == true)
{
arr[(int)ch] = true;
}
else
{
Console.WriteLine("First non repeated character: " + ch);
repeated = true;
break;
}
}

if (repeated == false)
Console.WriteLine("No repeated characters");
Console.ReadLine();
}
}
}

Comments

Popular posts from this blog

Network Security: LAN manager authentication level

Cisco AnyConnect Secure Mobility Client - VPN service not available. The VPN agent service is not responding