Wednesday, 21 December 2016

Java program to find duplicate element in an array

public class Answer implements QuestionInterface
 {
@Override
public char  func (String s){
char[] ch=s.toCharArray();
        int i,j;
        char b = 0;
        for(i=0;i<s.length();i++)
        {
            for(j=i+1;j<s.length();j++)
            {
                if(ch[j]==ch[i])
                {
                    b=ch[j];
                    break;
                }
            }
        }
        return b;
}
}

6 comments: