Posts

Showing posts with the label First repeated character

First repeated character

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace FirstRepeatedCharacter1 { class Program { static void Main(string[] args) { Console.WriteLine("Enter the string"); string str = Console.ReadLine(); if (str == "") { Console.WriteLine("string is empty"); Console.ReadLine(); return; } bool repeated = false; Hashtable strhash = new Hashtable(); foreach (char ch in str) { if (strhash.ContainsValue(ch)) { Console.WriteLine("First non repeated character: " + ch); repeated = true; break; } else { strhash.Add((int)ch, ch); } } if (repeated == false) { Console.WriteLine("No repeated characters"); } Console.ReadLine(); } } }