text: Find repeated character present first in a string | C # program to find the first character that is repeated ; this is O ( N ^ 2 ) method ; Driver code
code: using System ; class GFG { static int findRepeatFirstN2 ( string s ) { int p = - 1 , i , j ; for ( i = 0 ; i < s . Length ; i ++ ) { for ( j = i + 1 ; j < s . Length ; j ++ ) { if ( s [ i ] == s [ j ] ) { p = i ; break ; } } if ( p != - 1 ) break ; } return p ; } static public void Main ( ) { string str = " geeksforgeeks " ; int pos = findRepeatFirstN2 ( str ) ; if ( pos == - 1 ) Console . WriteLine ( " Not ▁ found " ) ; else Console . WriteLine ( str [ pos ] ) ; } }